简体   繁体   English

如何在运行时创建Azure SQL数据库副本?

[英]How do I create an Azure SQL Database copy during runtime?

I am new to VB.NET and Azure SQL services and I have spent the last 3 days searching for an answer and cannot come up with an answer I can truly understand. 我是VB.NET和Azure SQL服务的新手,我过去三天一直在寻找答案,但无法提出我能真正理解的答案。 Here is my scenario and problem: 这是我的情况和问题:

I have a VB.NET application where a user will log into their account and have their own set of tables under their own Azure SQL Database. 我有一个VB.NET应用程序,用户可以在其中登录自己的帐户,并在自己的Azure SQL数据库下拥有自己的表集。 I would like my program to automatically create their database for them (using their own selected name), which would be a database copy of an existing empty Database in Azure. 我希望程序为他们自动创建数据库(使用他们自己选择的名称),这将是Azure中现有空数据库的数据库副本。

I can already access the data tables in my master database, but I do not know how to make a copy of it from my program during runtime. 我已经可以访问主数据库中的数据表,但是我不知道如何在运行时从程序中复制它。 When I run my application and it debugs the following snippit of code, I get an exception error saying "You must be logged into the master database" I'm not sure how to resolve that error from popping up as I am using the master admin account in my normal SQL connection string. 当我运行应用程序并调试以下代码段时,出现异常错误,提示“您必须登录到主数据库”,我不确定如何解决该错误,因为我正在使用主管理员我的普通SQL连接字符串中的帐户。

Private Sub BtnActivate_Click(sender As Object, e As RoutedEventArgs)
    If passwrd1.Password <> passwrd2.Password Then
        MsgBox("Password doesn't match Confirm Password.", vbOKOnly)
    Else
        Dim commandString = "CREATE DATABASE " & dbname.Text & " AS COPY OF DBDEV;"
        Using connection As New SqlConnection(My.Settings.DBDEVConnectionString)
            Dim command As New SqlCommand(commandString, connection)
            Try
                connection.Open()
                command.ExecuteNonQuery()
                MsgBox("DATABASE SETUP.  USE " & dbname.Text & "AS DBNAME TO CONNECT TO")
            Catch ex As Exception
                Throw ex
            End Try
        End Using
    End If
End Sub

Please help, I've been moving nowhere and everything I'm searching for doesn't give me a clear answer to this simple scenario. 请帮忙,我一直走不动,我正在寻找的所有内容都无法为我提供这种简单情况的明确答案。

After many attempts, I solved the problem: in my connection string, I had the initial catalog default to my database and so I changed it to say "master" (even though I don't have a database named master) and it performed the Database copy for me. 经过多次尝试,我解决了问题:在连接字符串中,我将初始目录默认设置为数据库,因此将其更改为“ master”(即使我没有名为master的数据库),并且它执行了数据库副本给我。 Woohoo! 哇噢!

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

相关问题 如何复制SQL Server数据库 - How do I copy a SQL Server database 如何在运行时在Delphi中使用SQL在Access数据库中创建计算字段 - How to create calculated field in Access Database using SQL during runtime in Delphi 如何将SQL Server 2012数据库复制到localdb实例? - How do I copy SQL Server 2012 database to localdb instance? 使用 Azure Sql 从 C# 应用程序副本创建数据库 - create a database from a copy C# application using Azure Sql 如何在Azure中设置SQL数据库镜像 - How Do I setup SQL Database Mirroring In Azure 如何创建生产SQL数据库的副本? - How to create copy of production SQL database? 在SQL插入上,在事务期间,如何获取新行中另一个字段的值以复制到另一个字段? - On SQL Insert, during the transaction, how do I get the value of another field in this new row to copy to another field? 如何将数据从一个 Azure 数据库表复制到另一个 Azure 数据库表并转换数据类型? - How do I copy data from one Azure database table to a different Azure database table and also convert data types? 如何在现有的Azure SQL数据库中创建联合 - How to create federation in an existing azure sql database 如何使用JDBI的Sql Object API在运行时创建动态Sql查询? - How do I create a Dynamic Sql Query at runtime using JDBI's Sql Object API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM