相对路径似乎不适用于sqlite [英] relative path doesn't seem to work for sqlite

查看:651
本文介绍了相对路径似乎不适用于sqlite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi all i'm using sqlite db with winforms c#.
My code runs fine when i use the absolute path
SQLiteConnection m_dbConnection = new SQLiteConnection(@"Data Source=D:\Test\1\1\test.sqlite;");
but the problem starts when i use the relative path,if i use in the page behind i.e in .cs
string con = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
i have a app.config in which i have the following code

<configuration>
  <connectionStrings>
    <add name="connection" connectionString="Data Source=|DataDirectory|\test.sqlite; ProviderName=System.Data.SqlLite;"/>
  </connectionStrings>
</configuration>

SQL logic error or missing database
no such table:customers.
using AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))
also didn help me.I have done alot of serach on gooogle but seemed no much help to me. Any help would be greatly appreciated. Thanku

推荐答案

尝试离开尾巴'\':

Try leaving off the tail '\':
<configuration>
  <connectionStrings>
    <add name="connection" connectionString="Data Source=|DataDirectory|test.sqlite; ProviderName=System.Data.SqlLite;"/>
  </connectionStrings>
</configuration>

这篇关于相对路径似乎不适用于sqlite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆