安装后将数据库附加到SQL Server

编程入门 行业动态 更新时间:2024-10-24 06:26:23
本文介绍了安装后将数据库附加到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

本文发布于:2023-11-10 01:02:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后将   数据库   Server   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!