我有以下代碼:我無法連接到數據庫在Visual Basic中
Dim string_conectare As String = "Data Source=|DataDirectory|\Database1.sdf"
Dim conexiune As SqlConnection
conexiune = New SqlConnection(string_conectare)
conexiune.Open()
If conexiune.State = ConnectionState.Open Then
MsgBox("OK")
Else
MsgBox("not ok")
End If
正如你可以看到我想開到我要測試它,我得到這個錯誤的數據庫,但每一次的連接:
A network-related or instance-specific error occurred while establishing a
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is
configured to allow remote connections. (provider: SQL Network Interfaces,
error: 26 - Error Locating Server/Instance Specified)
我掙扎了2個多小時,所以請幫幫我!
後來編輯:
我已經試過這樣:
Dim string_conectare As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database1.sdf;Persist Security Info=True"
Dim conexiune As OleDbConnection
conexiune = New OleDbConnection(string_conectare)
conexiune.Open()
If conexiune.State = ConnectionState.Open Then
MsgBox("OK")
Else
MsgBox("not ok")
End If
,但它把我這個錯誤:
Unrecognized database format
@EmilDumbazu:看看這是否有幫助? http://www.sswug.org/articlesection/default.aspx?TargetID=44331 –
@SiddharthRout我使用2008版本,該文章中的第一個「提示」是關於2005版本 –
@EmilDumbazu:這會給你一個基本的想法是什麼可能是錯的。 :) 那這個呢? http://stackoverflow.com/questions/360141/how-to-connect-to-local-instance-of-sql-server-2008-express –