gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:47:03 25 4
gpt4 key购买 nike

我想在 Azure SQL Server 中创建一个数据库,我已浏览以下链接: https://learn.microsoft.com/en-us/sql/relational-databases/databases/sql-server-data-files-in-microsoft-azure

但这并没有解决我的问题,反而把我带到了另一个结局。

我有以下脚本,我必须使用 Management Studio 在 SQL Server 上执行我可以在本地计算机上执行它,但我不知道应该在此处使用什么路径 ('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存储帐户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

关于sql-server - 在 Azure SQL Server(逻辑服务器)中使用文件组创建数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47203320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com