开发者

What is wrong on connection string

I am trying to connect database.sdf on same director. Using following code but gives me connection error. What I am doing wrong. Please hel开发者_JAVA百科p me.

    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)


I think you're missing some code... or maybe that's the problem, you never bind your SqlCeConnection to 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)


You do not need the single quotes (') in the different parts of the connection string, and you should be using a semi-colon (;) to separate the different values.

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

Apart from that, you do not appear to be using the connection string in your code. You should be using it to open the connection:

con = New SqlCeConnection(connstring)


Check out Connection Strings for great connection string assitance.

It looks like your line:

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

is using both "," and ";" to separate the parameters. Update then all to use ";"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜