为什么SqlServerCe连接拒绝文件名 [英] Why SqlServerCe connection rejects the file name
问题描述
你好,
我创建了一个SQL Server Compact 3.5数据库文件(sword.sdf),并在VS 2008中定义了连接字符串,如下所示:
Hello,
I created a SQL Server Compact 3.5 database file (sword.sdf) I defined the connection string in VS 2008 as follows:
Dim AppPath As String = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim ConnStr As String = "Data Source='" + AppPath + "\sword.sdf';Persist Security Info=True;password='12111964';"
我收到一条错误消息,提示文件名不是有效的文件名" .
文件名没有问题.我确实在服务器资源管理器中测试了数据库连接.它连接到数据库.但是在运行时,我收到错误消息.
您知道什么可能导致问题吗?
谢谢.
I get an error message saying that "The file name is not a valid file name".
Nothing is wrong with the file name. I did test the database connection in server explorer. It connects to the database. But at runtime, I get the error message.
Do you know what could be causing the problem?
Thanks.
推荐答案
我想如果您检查一下,那System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
返回以"file:"开头的路径,这会混淆正常处理.
尝试使用:
I think if you check, thatSystem.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
returns a path preceded by "file:" which will confuse the normal processing.
Try using:
Dim AppPath As String = Directory.GetCurrentDirectory()
在启动时使用它,并将连接字符串存储在类级别的变量中,因此您无需重新生成它(CurrentDirectory可以在您的App运行时更改.)
Use it at startup, and store your connection string in a class level variable so you don''t have to re-generate it (CurrentDirectory can change while your App is running.)
这篇关于为什么SqlServerCe连接拒绝文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!