我试图在连接到本地SQL Server Express实例时附加位于数据目录中的数据库文件。 我收到一条消息:无法打开物理文件“D:\ Project1 \ bin \ Debug \ Database \ db_project_log.ldf”。操作系统错误32:“32(进程无法访问该文件,因为它正被另一个进程使用。)”。
请看下面的代码:
Sub GetData()
Dim cnGS As ADODB.Connection
Dim rsSelect As ADODB.Recordset
cnGS = CreateObject("ADODB.Connection")
rsSelect = CreateObject("ADODB.Recordset")
With cnGS
.Provider = "SQLNCLI"
.Mode = ConnectModeEnum.adModeReadWrite
.ConnectionString = "SERVER=.\SQLExpress;AttachDbFilename=" _
& Application.StartupPath & "/Database/db_project.mdf;" & _
"Database=db_project; Trusted_Connection=Yes;"
.Open()
End With
Dim sSQLSelect = "SELECT * FROM v_billing WHERE bill_id = 123"
rsSelect.Open(sSQLSelect, cnGS, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockReadOnly)
rsSelect.MoveFirst()
End Sub
任何想法如何做到这一点?