在 Azure SQL 服务器(逻辑服务器)中使用文件组创建数据库
Create database with filegroups in Azure SQL Server (Logical Server)
我想在 Azure SQL 服务器中创建一个数据库我已经完成了以下 link :
https://docs.microsoft.com/en-us/sql/relational-databases/databases/sql-server-data-files-in-microsoft-azure
但这并没有解决我的问题,它把我带到了另一个目的。
我有以下脚本,我必须使用 management studio 在 SQL 服务器上执行我可以在我的本地计算机上执行它,但我不知道我应该在这里使用什么路径 ('D:\Databases\xxxxx.ldf')
对于 Azure
CREATE DATABASE [xxxxx] ON PRIMARY
( NAME = N'xxxxx_Config', FILENAME = N'D:\Databases\xxxxx.mdf' , SIZE = 14336KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ),
FILEGROUP [SECONDARY]
( NAME = N'xxxxx_Content', FILENAME = N'D:\Databases\xxxxx_1.ndf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'xxxxx_log', FILENAME = N'D:\Databases\xxxxx.ldf' , SIZE = 2377088KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
@DanielG 帮我找到了方法。实际上,如果您使用的是 PaaS,则无法获得物理路径,但是如果您设置了自己的 VM,则可以实现。我通过从 azure 更改我的部署服务器解决了这个问题。
更新:
谢谢@DanielG
最近,我通过在 Azure 存储中创建容器并在容器中创建 blob 来实现此目的。以下是步骤:
1. 首先你必须创建 azure storage account
2. 创建一个容器。
3. 保存连接字符串。
4. 创建一个 blob。
这是将图像文件添加到 blob 的代码。
string _fileName = "";
string _uri = "";
string _localPath = "";
string _size = "";
MemoryStream ms = null;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));//defined in webconfig
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("imagecontainer");//your containner name in azure storage
_fileName = DateTime.UtcNow.ToString("HHmmss") + "_" + images.FileName + ".jpg";//set the file name as you like
CloudBlockBlob blockBlob = container.GetBlockBlobReference(_fileName);
blockBlob.Properties.ContentType = "image/jpg";
ImageHelper _ih = new ImageHelper();
ms = new MemoryStream(_ih.Resize2Max50Kbytes(images.Image1).ToArray());//its just some additional work
ms.Seek(0, SeekOrigin.Begin);
string imageFullPath = blockBlob.Uri.ToString();
using (var fs = ms)
{
await blockBlob.UploadFromStreamAsync(fs);
}
_uri = blockBlob.Uri.AbsolutePath; //here you will get the path which you can keep in database.
_size = blockBlob.StreamWriteSizeInBytes.ToString();
_localPath = blockBlob.Uri.LocalPath;
var result = _entities.Images.SingleOrDefault(b => b.Id == images.Id);
_mainLog.Info("Image added: " + images.FileName);
if (result != null)
{
result.FileName = _uri;
result.Image1 = null;
_entities.SaveChanges();
}
_processedCounter++;
下图将有助于在 azure 中创建容器。
我想在 Azure SQL 服务器中创建一个数据库我已经完成了以下 link : https://docs.microsoft.com/en-us/sql/relational-databases/databases/sql-server-data-files-in-microsoft-azure
但这并没有解决我的问题,它把我带到了另一个目的。
我有以下脚本,我必须使用 management studio 在 SQL 服务器上执行我可以在我的本地计算机上执行它,但我不知道我应该在这里使用什么路径 ('D:\Databases\xxxxx.ldf')
对于 Azure
CREATE DATABASE [xxxxx] ON PRIMARY
( NAME = N'xxxxx_Config', FILENAME = N'D:\Databases\xxxxx.mdf' , SIZE = 14336KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ),
FILEGROUP [SECONDARY]
( NAME = N'xxxxx_Content', FILENAME = N'D:\Databases\xxxxx_1.ndf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'xxxxx_log', FILENAME = N'D:\Databases\xxxxx.ldf' , SIZE = 2377088KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
@DanielG 帮我找到了方法。实际上,如果您使用的是 PaaS,则无法获得物理路径,但是如果您设置了自己的 VM,则可以实现。我通过从 azure 更改我的部署服务器解决了这个问题。
更新:
谢谢@DanielG
最近,我通过在 Azure 存储中创建容器并在容器中创建 blob 来实现此目的。以下是步骤: 1. 首先你必须创建 azure storage account 2. 创建一个容器。 3. 保存连接字符串。 4. 创建一个 blob。
这是将图像文件添加到 blob 的代码。
string _fileName = "";
string _uri = "";
string _localPath = "";
string _size = "";
MemoryStream ms = null;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));//defined in webconfig
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("imagecontainer");//your containner name in azure storage
_fileName = DateTime.UtcNow.ToString("HHmmss") + "_" + images.FileName + ".jpg";//set the file name as you like
CloudBlockBlob blockBlob = container.GetBlockBlobReference(_fileName);
blockBlob.Properties.ContentType = "image/jpg";
ImageHelper _ih = new ImageHelper();
ms = new MemoryStream(_ih.Resize2Max50Kbytes(images.Image1).ToArray());//its just some additional work
ms.Seek(0, SeekOrigin.Begin);
string imageFullPath = blockBlob.Uri.ToString();
using (var fs = ms)
{
await blockBlob.UploadFromStreamAsync(fs);
}
_uri = blockBlob.Uri.AbsolutePath; //here you will get the path which you can keep in database.
_size = blockBlob.StreamWriteSizeInBytes.ToString();
_localPath = blockBlob.Uri.LocalPath;
var result = _entities.Images.SingleOrDefault(b => b.Id == images.Id);
_mainLog.Info("Image added: " + images.FileName);
if (result != null)
{
result.FileName = _uri;
result.Image1 = null;
_entities.SaveChanges();
}
_processedCounter++;
下图将有助于在 azure 中创建容器。