简体   繁体   English

通过SSMS使用Azure本地开发存储(SQL Server Management Studio)

[英]Working with Azure local Development Storage via SSMS (sql server management studio)

I am trying to write code to access my azure local development storage. 我正在尝试编写代码以访问我的Azure本地开发存储。 I started off by creating a new storage for myself: 我首先为自己创建了一个新存储:

dsInit /forceCreate

I can now see the DevelopmentStorageDb20090919 in SSMS with some precreated tables such as dbo.TableContainer, dbo.TableRow etc. 现在,我可以在SSMS中看到带有一些预先创建的表的DevelopmentStorageDb20090919,例如dbo.TableContainer,dbo.TableRow等。

  1. Now, can I simply add tables to this database via SSMS (ex. Employee table) and start accessing them via code ? 现在,我可以简单地通过SSMS(例如Employee表)将表添加到该数据库并开始通过代码访问它们吗? Is this the right way to do stuff ? 这是做事情的正确方法吗?

For example: 例如:

    var svc = CloudStorageAccount.DevelopmentStorageAccount
.CreateCloudTableClient().GetDataServiceContext();

                //"Employees" is the name of the table                
                svc.AddObject("Employees", new Employees("John Doe"));    
                svc.SaveChangesWithRetries();

2 . 2。 And additionally, once I am all done, how do I port the table and the data into the actual cloud account ? 另外,一旦完成,如何将表和数据移植到实际的云帐户中? By running scripts there ? 通过在那里运行脚本?

I think you're confusing Azure Table Storage with SQL Server or SQL Azure, which are completely different. 我认为您将Azure Table Storage与SQL Server或SQL Azure混淆了,这是完全不同的。 You cannot access Azure Storage tables at all with SSMS. 您无法使用SSMS访问Azure存储表。 The code sample you provided is using the Azure SDK (which is using the Storage REST API underneath). 您提供的代码示例使用的是Azure SDK(其下面使用的是Storage REST API)。 That's the only way to access Azure Storage. 这是访问Azure存储的唯一方法。

If you want to create / view tables in a more graphical way, try Cerebrata's Cloud Storage Studio , ClumsyLeaf's AzureXplorer , David Pallman's Azure Storage Explorer , or some other similar tool. 如果要以更图形化的方式创建/查看表,请尝试使用Cerebrata的Cloud Storage Studio ,ClumsyLeaf的AzureXplorer ,David Pallman的Azure Storage Explorer或其他类似工具。 These tools all rely on the SDK or direct API calls. 这些工具都依赖于SDK或直接API调用。

Now, regarding your code: You need to create your table before inserting objects. 现在,关于您的代码:您需要在插入对象之前创建表。 See CreateTablesFromModel() and CreateTableIfNotExist(). 请参见CreateTablesFromModel()和CreateTableIfNotExist()。 The Azure Platform Training Kit has a great intro/lab for creating and using tables, and shows how to use CreateTablesFromModel(). Azure平台培训工具包具有用于创建和使用表的出色的入门/实验,并演示了如何使用CreateTablesFromModel()。

As long as that table exists, then yes, the code you have written will add "John Doe" to the employees table. 只要该表存在,就可以,您编写的代码会将“ John Doe”添加到employees表中。 While it can be interesting to look at data through SSMS and you could try altering data that way, I wouldn't recommend trying it. 通过SSMS查看数据可能会很有趣,并且您可以尝试以这种方式更改数据,但我不建议您尝试这样做。 Development storage is funny enough without poking it with a stick. 开发存储足够有趣,而无需用棍子戳它。 There are differences between dev storage and actual cloud storage, so I have found that the sooner you can stop using dev storage the better. 开发存储和实际云存储之间存在差异,因此我发现越早停止使用开发存储就越好。

At the moment there is no fancy way of transferring data between Azure tables (be they in dev storage or in the cloud). 目前,还没有一种在Azure表之间传输数据的理想方法(无论是在开发存储中还是在云中)。 It boils down to running a query that selects everything from the source table, then writes each individual item to the destination table. 它归结为运行查询,该查询从源表中选择所有内容,然后将每个单独的项目写入目标表。 Depending on how your data is partitioned you might be able to batch the writes or you might be able to do them in parallel. 根据数据的分区方式,您可能可以批处理写操作,也可以并行执行写操作。 If you're willing to use the REST API directly you could avoid the storage library having to deserialise each item before it's written. 如果您愿意直接使用REST API,则可以避免存储库在编写每个项目之前都必须对其进行反序列化。

Even though it's best to use the APIs to talk to the DevStorage, there might be scenarios where the direct database access could prove beneficial. 即使最好使用API​​与DevStorage进行通信,但在某些情况下,直接数据库访问可能被证明是有益的。 More specifically, it can be used to circumvent some SDK issues that are specific to DevStorage. 更具体地说,它可用于规避一些DevStorage特有的SDK问题。

I once ran into a problem with renaming of large blobs - the operation would simply time out (note that blobs cannot be renamed - they first need to be copied using CopyFromBlob() and then deleted). 我曾经遇到过重命名大Blob的问题-该操作只会超时(请注意,无法重命名Blob-首先需要使用CopyFromBlob()复制它们,然后将其删除)。 I tried both in Azure Storage Explorer and by writing code and increasing all the timeouts. 我在Azure存储资源管理器中都尝试过,并且通过编写代码并增加了所有超时来进行尝试。 Solution? 解? SQL to the rescue! SQL来解救!

Here is an example of SQL that would rename a blob within a container or move it to a different one: 这是一个SQL示例,它将重命名容器中的Blob或将其移动到另一个容器中:

begin tran

alter table CommittedBlock nocheck constraint BlockBlob_CommittedBlock

update CommittedBlock set BlobName = @TargetBlobName, ContainerName = @TargetContainerName where BlobName = @SourceBlobName and ContainerName = @SourceContainerName
update BlockData set BlobName = @TargetBlobName, ContainerName = @TargetContainerName where BlobName = @SourceBlobName and ContainerName = @SourceContainerName
update Blob set BlobName = @TargetBlobName, ContainerName = @TargetContainerName where BlobName = @SourceBlobName and ContainerName = @SourceContainerName

alter table CommittedBlock with check check constraint BlockBlob_CommittedBlock

rollback tran

Of course, use it at your own risk - this is a completely unsupported way of working with dev stotage. 当然,使用它需要您自担风险-这是使用开发存储的一种完全不受支持的方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署在本地SQL Server Management Studio中的Azure数据库的数据库备份 - Database backup of azure database deployed in local sql server management studio 如何使用C#在SSMS(SQL Server Management Studio)17的标题栏中设置自定义文本 - How to set custom text in titlebar of SSMS(SQL Server Management Studio) 17 using c# SQL无法在C#上运行,但可以在SQL Server Management Studio中运行 - SQL not working on c# but working in SQL Server Management Studio 在Visual Studio或SQL Server Management Studio中连接到Azure SQL数据库的哪些必要步骤? - Which are necessary steps to connect to an Azure SQL database in Visual Studio or SQL Server Management Studio? SQL Server Management Studio中的架构 - Schema in SQL Server Management Studio SQL Server Management Studio中的复选框 - Checkbox in SQL Server Management Studio SQL Server 2008 datetime不会通过c#插入,但可以在SQL Server Management Studio中使用吗? - SQL Server 2008 datetime will not insert via c# but works within SQL Server Management Studio? 通过 Visual Studio 2017 VSIX 项目构建 SQL Server Management Studio 扩展:为 AsyncPackage 类绕过 Initialiaze() - Building a SQL Server Management Studio Extension via Visual Studio 2017 VSIX project: Bypass Initialiaze() for AsyncPackage class 使用sql server管理工作室和C#编码在AZURE中运行.SQL脚本很长时间 - Taking to long time to run .SQL Script in AZURE using sql server management studio and C# coding C# - XLSX 到 SQL Server - OpenRecordSet 不适用于 C#,但适用于 MS SQL Server Management Studio - C# - XLSX to SQL Server - OpenRecordSet not working in C# but works in MS SQL Server Management Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM