本文介绍了安装后将数据库附加到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在安装应用程序之后,我需要将数据库附加到SQL Server.我正在使用以下代码.

Hi,
Just after installing my application, I need to attach my DB to SQL server. I am using following code for it.

Dim cmd As New SqlCommand()
       Dim vrMyConString As String = "Data Source=.\SQLExpress; INITIAL CATALOG=master; uid=sa; pwd=sa;"
       Dim conn As System.Data.SqlClient.SqlConnection = New SqlConnection(vrMyConString)
       cmd.CommandText = "sp_attach_db 'e:\dbTest.mdf', 'e:\dbTest.ldf'"
       ' conn.ConnectionString = "Data Source=.\SQLExpress; INITIAL CATALOG=master; uid=sa; pwd=sa;"
       conn.Open()
       cmd.CommandType = CommandType.StoredProcedure
       cmd.Connection = conn
       cmd.executenonquery()



它在
上给出错误cmd.executenonquery()
无法在sysdatabases中找到数据库''sp_attach_db''e:\ dbTest''的条目.找不到具有该名称的条目.确保正确输入了该名称."

请告知我该怎么办.
谢谢



It gives error on
cmd.executenonquery()
"Could not locate entry in sysdatabases for database ''sp_attach_db ''e:\dbTest''. No entry found with that name. Make sure that the name is entered correctly."

Please advise what do I need to do.
Thanks

推荐答案


这篇关于安装后将数据库附加到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 23:28