[英]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.