任何人都可以通过此连接字符串帮助我。我无法管理如何修复。
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()
由于
答案 0 :(得分:4)
该字符串包含一段现在不会被执行的代码。我想你的意思是:
constring = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\database.sdf;Password=pswrd;File Mode=shared read"
答案 1 :(得分:1)
我不确定是否还有其他问题但是代码应该在字符串之外!
constring = String.Format("Data Source ={0}\\database.sdf;Password=pswrd;File Mode=shared read",(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase))
答案 2 :(得分:1)
如果您想使用登录详细信息:
constring = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \database.sdf; Password = pswrd"
但你不必:
constring = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + \database.sdf; Persist Security Info = false"
我倾向于使用完整的文件路径:
constring = @"Data Source=C:\...\database.sdf;Persist Security Info=False";