Reputation: 141
Can any one help me with this connection string. I can't manage how to fix.
Dim constring As String
Dim con As SqlCeConnection
Dim cmd As SqlCeCommand
constring = "(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \\database.sdf;Password=pswrd;File Mode=shared read"
con = New SqlCeConnection()
con.Open()
Thanks
Upvotes: 0
Views: 438
Reputation: 703
If you want to use login details:
constring = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \database.sdf; Password = pswrd"
But you don't have to:
constring = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \database.sdf; Persist Security Info = false"
I tend to use the full file path:
constring = @"Data Source=C:\...\database.sdf;Persist Security Info=False";
Upvotes: 1
Reputation: 453920
I'm not sure if there are any other problems but definitely the code should be outside the string!
constring = String.Format("Data Source ={0}\\database.sdf;Password=pswrd;File Mode=shared read",(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase))
Upvotes: 1
Reputation: 3560
The string contains a piece of code that will now not be executed. I think you mean:
constring = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\database.sdf;Password=pswrd;File Mode=shared read"
Upvotes: 4