安装后将数据库附加到SQL Server [英] Attaching DB to SQL Server just after installation

查看:71
本文介绍了安装后将数据库附加到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数据库 [
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆