Click here to Skip to main content
15,886,100 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
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
Posted
Updated 14-May-20 0:53am

Try leaving off the tail '\':
XML
<configuration>
  <connectionStrings>
    <add name="connection" connectionString="Data Source=|DataDirectory|test.sqlite; ProviderName=System.Data.SqlLite;"/>
  </connectionStrings>
</configuration>
 
Share this answer
 
Comments
Pankaja Kanavi 1-Oct-13 7:13am    
i tried doesn't work
Mehdi Gholam 1-Oct-13 7:17am    
Put a break point on the connection string and see what is being returned for DataDirectory.
Pankaja Kanavi 1-Oct-13 7:28am    
Hi mehdi m getting
Data Source=|DataDirectory|\test.sqlite; ProviderName=System.Data.SqlLite;
it's possible
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="Default" connectionString="Data Source=|DataDirectory|\DBBHC.db" providerName="System.Data.SQLite" />
  </connectionStrings>






move your db into app_data folder and use


using (SQLiteConnection conn = new SQLiteConnection(LoadConnectionString()))
            {

                var output = conn.Query<string>("select * from ProjectLists", new DynamicParameters());}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900