tags:

views:

73

answers:

3

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

+1  A: 

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))
Martin Smith
It says unknown connection option in connection string
Hakan
See Edit. I think you need a `Data Source =` in there as well. My VB.NET might be slightly dodgy but should give you the idea!
Martin Smith
Great that works. Thank you Martin
Hakan
+3  A: 

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"
Marc
It says unknown connection option in connection string
Hakan
Thanks Mark. You are great
Hakan
+1  A: 

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";
Sir Graystar