在Azure SQL Server(逻辑服务器)中使用文件组创建数据库

时间:2017-11-09 13:37:46

标签: sql-server azure azure-storage azure-sql-server

我想在Azure SQL服务器中创建一个数据库我已经通过以下链接: https://docs.microsoft.com/en-us/sql/relational-databases/databases/sql-server-data-files-in-microsoft-azure

但这并没有解决我的问题,而是让我走到了另一端。

我有以下脚本,我必须使用管理工作室在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

1 个答案:

答案 0 :(得分:0)

@DanielG帮我找到了办法。实际上,如果您使用PaaS,那么您无法获得物理路径,但是如果您已经设置了自己的VM,则可以实现这一点。我通过从azure更改我的部署服务器解决了这个问题。

<强>更新

感谢@DanielG

最近,我通过在azure存储中创建容器并在容器中创建blob来实现此目的。以下是步骤: 1.首先,您必须创建azure存储帐户 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中创建容器。

enter image description here