本文介绍了安装后将数据库附加到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 Express数据库 [ ^ ] 我会在该部分尝试以下内容,看看是否有任何错误. 否则,我将检查用户安全性以确保他们具有足够的权限,并且可以通过Management Studio等手动连接到已安装的SQL Express. Have you tried this? Connecting to a SQL Server Express Database[^] I would try the following in that section and see if you get any errors. Otherwise I would look at user security to make sure they have enough permissions and that you can manually connect to the installed SQL Express through management studio etc.
更多推荐
安装后将数据库附加到SQL Server
发布评论