Reputation: 490
I want to create a database within Azure SQL server I have gone through the following link : https://learn.microsoft.com/en-us/sql/relational-databases/databases/sql-server-data-files-in-microsoft-azure
but this didn't solve my problem and it took me to another end.
I have the following script which I have to execute on SQL server using management studio I can execute it on my local machine but I don't know what path should I use here ('D:\Databases\xxxxx.ldf')
for 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
Upvotes: 2
Views: 4235
Reputation: 490
@DanielG helped me to find a way. Actually if you are using PaaS then there is no way you can get the physical path but yes if you have setup your own VM then this can be achieved. I solved this issue by changing the my deployment server from azure.
Update:
thanks @DanielG
Recently, I did this by creating the container in the azure storage and blobs in the container. following are the steps: 1. First you have to create the azure storage account 2. Create a container. 3. Save the connection string. 4. Create a blob.
Here is the code to add an image file to the 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++;
Following image will help to create the container in azure.
Upvotes: 2