【发布时间】:2012-06-05 19:55:24
【问题描述】:
我有以下代码:
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:看看这是否有帮助? sswug.org/articlesection/default.aspx?TargetID=44331
-
@SiddharthRout 我使用的是 2008 版本,那篇文章中的第一个“提示”是关于 2005 版本的
-
@EmilDumbazu:这会给你一个基本的想法,什么可能是错的。 :) 那这个呢? stackoverflow.com/questions/360141/…
标签: database vb.net connection-string