连接字符串有什么问题

时间:2010-06-04 16:03:40

标签: sql vb.net

我正在尝试在同一个导演上连接database.sdf。使用以下代码,但给我连接错误。我做错了什么。请帮帮我。

    Dim connstring As String
    Dim con As SqlCeConnection
    Dim command As SqlCeCommand
    connstring = "Persist Security Info = False; Data Source = '.\database.sdf', Password = 'pswrd', File Mode = 'shared read'"
    con = New SqlCeConnection
    con.Open()
    command = New SqlCeCommand("select * from users where Name=? and Password=?", con)

3 个答案:

答案 0 :(得分:2)

我认为你错过了一些代码......或许这就是问题,你永远不会将你的SqlCeConnection绑定到connstring

Dim con As SqlCeConnection
Dim command As SqlCeCommand
con = New SqlCeConnection("Persist Security Info=False;Data Source=.\database.sdf;Password=pswrd;File Mode=shared read")
con.Open()
command = New SqlCeCommand("select * from users where Name=? and Password=?", con)

答案 1 :(得分:2)

在连接字符串的不同部分中不需要单引号('),并且您应该使用分号(;)来分隔不同的值。

"Persist Security Info = False; Data Source = .\database.sdf; Password = pswrd; File Mode = shared read;"

除此之外,您似乎在代码中使用连接字符串。您应该使用它来打开连接:

con = New SqlCeConnection(connstring)

答案 2 :(得分:0)

查看Connection Strings以获得出色的连接字符串帮助。

看起来像你的行:

  

connstring =“Persist Security Info = False; Data Source ='。\ database.sdf',Password ='pswrd',File Mode ='shared read'”

同时使用“,”和“;”分开参数。然后更新所有使用“;”