Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to determine the connection string to a SQLite database, in C# code

$
0
0

Hello. I'm trying to figure out how to specify the connection string to a SQLite database, I would like to access using the following code:

            string connectionString = null;
            SqlConnection connection;
            SqlCommand command;

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds1 = new DataSet();
            string sql = "SELECT DataName, Data, Id, UserId, DateLastUpdated FROM MainTable";

            connectionString = "Data Source=C:\\SQLITEDATABASES\\SQLITEDB1.sqlite;Version=3;";


            connection = new SqlConnection(connectionString);
            try
            {
                connection.Open();
                command = new SqlCommand(sql, connection);
            }
            catch
            {
            }

The value I assigned to the variable connectionString, in the code above, I obtained somewhere from the Internet. It does not work. I'm using Visual Studio 2013, against the file sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe, which I installed, and got from here.

My application's App.config file looks as follows:

<?xml version="1.0" encoding="utf-8"?><configuration><configSections></configSections><connectionStrings><add name="DC_Password_Saver.Properties.Settings.DC_Password_SaverConnectionString" connectionString="data source=&quot;C:\Users\patmo_000\Documents\Visual Studio 2013\Projects\DC Password Saver\DC Password Saver\DC Password Saver.db&quot;" providerName="System.Data.SQLite.EF6"/></connectionStrings><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>

I tried to use the value assigned to connectionString in the XML settings above, replacing single backslash characters with double backslash characters, because the Visual Studio editor flagged them as unrecognizable, and wound up with the following.

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds1 = new DataSet();
            string sql = "SELECT DataName, Data, Id, UserId, DateLastUpdated FROM MainTable";

            connectionString = "data source=&quot;C:\\Users\\patmo_000\\Documents\\Visual Studio 2013\\Projects\\DC Password Saver\\DC Password Saver\\DC Password Saver.db&quot;";


            connection = new SqlConnection(connectionString);
The above code however does not work either. So again, does anyone know how I can specify in C# code, a connection string to access my SQLite database? Thanks in advance for your reply.

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>