错误:为服务器 - 服务器名称附加数据库失败 [英] Error : attach database failed for server - server name

查看:93
本文介绍了错误:为服务器 - 服务器名称附加数据库失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写一个带有以下代码的设置,以便在VB.Net 2010中使用SMO将数据库附加到sql server 2008:



Dim srv As New Smo.Server()

Dim strDataFile As String =Application.StartupPath + \\ targetPatientLabWork.mdf

Dim logDataFile As String =Application.StartupPath + \dbPatientLabWork_log .ldf

Dim strCopyToFolderMdf As String =C:\Program Files \ Microsoft SQL Server \ MSSQL10_50.MSSQLSERVER \ MSSQL \DATA\dbPatientLabWork.mdf

FileCopy(strDataFile,strCopyToFolderMdf)

Dim strCopyToFolderLdf As String =C:\Program Files \ Microsoft SQL Server \ MSSQL10_50.MSSQLSERVER \ MSSQL \DATA\dbPatientLabWork_log.ldf

FileCopy(logDataFile,strCopyToFolderLdf)

Dim strColl As New System.Collections.Specialized.StringCollection

strColl.Add(dbPatientLabWork.mdf )

strColl.Add(dbPatientLabWork_log.ldf)

srv.AttachDatabase(dbPatientLabWork,strColl)< ===错误在这里======



运行时错误是在最后一行生成为服务器附加数据库失败 - 服务器名称

有人可以帮我解决上面提到的错误。



我尝试过:



1.服务器对象srv在测试时显示所有附加的数据库。



2.数据库的.mdf和.ldf文件会被复制到Sql Server的相关文件夹DATA,但数据库没有附加。

I' ve been writing a setup with the following code to attach a database to sql server 2008 using SMO in VB.Net 2010:

Dim srv As New Smo.Server()
Dim strDataFile As String = "Application.StartupPath + \dbPatientLabWork.mdf"
Dim logDataFile As String = "Application.StartupPath + \dbPatientLabWork_log.ldf"
Dim strCopyToFolderMdf As String = "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\dbPatientLabWork.mdf"
FileCopy(strDataFile, strCopyToFolderMdf)
Dim strCopyToFolderLdf As String = "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\dbPatientLabWork_log.ldf"
FileCopy(logDataFile, strCopyToFolderLdf)
Dim strColl As New System.Collections.Specialized.StringCollection
strColl.Add("dbPatientLabWork.mdf")
strColl.Add("dbPatientLabWork_log.ldf")
srv.AttachDatabase("dbPatientLabWork", strColl) <=== ERROR HERE ======

A runtime error is being generated in the last Line "Attach database failed for Server - Server Name"
Could someone help me sort out the error generated as mentioned above.

What I have tried:

1. The server object srv shows all attached databases when tested.

2. The .mdf and .ldf files of the Database do get copied to the relevant folder DATA of the Sql Server but the database does not get attached.

推荐答案

只是关闭问题..



使用文件完整目录路径设置strColl.Add值。
Just to close the question off..

Set the strColl.Add values with the files full directory path.


这篇关于错误:为服务器 - 服务器名称附加数据库失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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