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

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.

What does SQLite connection strings has to do with WPF?
You will find some valid connection strings here:
https://www.connectionstrings.com/sqlite/
But you cannot use the SqlConnection class to connect to a SQLite database. You will need to download and add a reference to the System.Data.SQLite library and then use the SQLiteConnection class:
connection = new System.Data.SQLite.SQLiteConnection(connectionString);
try
connection.Open();
command = new System.Data.SQLite.SQLiteCommand(sql, connection);
catch
Please refer to the following article for more information and an example of how to connect and read and write data from an SQLite database using C#:
http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/.
There is contains a link where you can download the required assemblies.
Hope that helps.
Please remember to mark helpful posts as answer to close your threads and then start a new thread in an approproate forum if you have a new question.

Similar Messages

  • How to find the CONNECTION STRING

    how to find the connection string through SQL Statement?
    salahuddin/salahuddin@CONNECTION_STRING
    Below is all about my sql version:
    DEFINE SQLPLUSRELEASE = "800060000" (CHAR)
    DEFINE _EDITOR         = "Notepad" (CHAR)
    DEFINE OVERSION = "Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options" (CHAR)
    DEFINE ORELEASE = "1002000100" (CHAR)

    In windows XP plateform your can find from the ServicesHow can you do that using SQL statement? Plus connect strings are not available in Services. In post 9i SQL*Plus we can do it in SQL statement like this
    SELECT '&&_CONNECT_IDENTIFIER'
    FROM dual;
    Note: This will work only in SQL*Plus.

  • How to determine the connection time?

    Hello!
    We have big troubles with our ConnectionPool. We have adapted most parts from the Book "Professional Java Server Programming" (Wrox Press).
    However, the connections are invalid (I/O Exceptions like "End of TNS Data Channel" or "Broken Pipe") after a while.
    The average up-time of our pool is approximately 24 hours.
    Now we want to drop renew the connections after a certain amount of time (let�s say 1 hour). To do this, we would need to determine the time when the connection has been established. How can this be done?
    I have looked into the DatabaseMetaData class, but did not find anything (at the first glance).
    PLEASE help me / us, the problem is really severe!
    Thanks in advance,
    Gregor Graf

    PLEASE help me / us, the problem is really severe!Where did you get the pool from? Is it your code? If so then are you sending a keep alive query - which would keep the connection active?
    If it isn't your code then are you explicitly returning the connections to the pool?
    Commercial pools don't typically drop connections. Some do which can be discovered by examining the configuration options for the pool that you have.
    If it is your code and you just want to add this, then you add a time value to each connection node. Each time a node is returned you set the time. You have a thread that runs and checks the time value, dropping any that are older than the value you want.

  • How to get the connection string at runtime

    Hi,
    I'm using Forms6i.
    I'm using EXEC_SQL to execute a dynamic sql in my form.
    I need connection string for that . But i cannot give it hardcodingly.
    Is there any form's properties to get the database connection string, to which the form is connected ?
    Thanks

    Hi,
    I've the user i/p columns
    EmpNo, Dept ,Holicode and , From and To Date.
    In which From and To Date is mandatory.
    In one table, emp_cal_header, i have all the holidays defined for each of the employees for a year.
    The records like
    EmpNo    Holicode     Holidt
    001        Frioff         02/07/2011
    001        Satoff        03/07/2011
    001        Frioff         08/07/2011
    .....So i want the final o/p in Excel like
    If user i/p is from Date: 01/07/2011 ,ToDate:09/07/2011, EmpNo :001
    EmpNo   Dept     Total  01/07/2011   02/07/2011 ..... 08/07/2011  09/07/2011
    001        IT        3               FriOff           Frioff            For this i'm constructing a dynamic sql like this
         qry := '(Select ech_emp_code cal_emp_code,emp_name CAL_EMP_NAME,emp_dept CAL_EMP_DEPT,count(ech_date) CAL_TOTAL'||date_cols||'
                             from (Select ech_emp_code,em.emp_name||'' ''||em.emp_middle_name||'' ''||em.emp_last_name emp_name,em.emp_dept emp_dept,ech_code,ech_desc,ech_date
                                            from emp_cal_header ,employee_master em
                                where emp_cal_header.ech_emp_code = em.emp_code
                                and  ech_emp_code = '||nvl(:emp_code,'ech_emp_code')
                                ||' and em.emp_status IN (''P'',''C'')'
                                ||' and em.emp_dept = '||dep
                                ||' and ech_date between '''||to_date(to_char(:From_dt,'DD-MON-YYYY'))
                                ||''' and '''  ||to_date(to_char(:To_dt,'DD-MON-YYYY'))
                                ||''' and ech_code = '||holi
                                ||' order by ech_Date)
                 group by ech_emp_code,emp_name,emp_dept)';
    and date_cols is constructed as
         todt := :from_dt ;
         i := 0;
         loop
              i := i+1;
              dt  := to_char(todt,'dd-MON-YYYY');
              date_cols     := date_cols||','||'max(decode(to_char(ech_date,''dd-MON-YYYY''),'''||dt||''',ech_CODE)) DT'||i;
              todt := todt + 1;
              Exit when todt > :to_dt ;
         End loop;This query i'm executing using EXEC_SQL.
    Since date_cols can be constructed only based on user i/p , i'm not able to do just a normal query
    Any help

  • C How to Set Isolation Level in the Connection String

    How to Set Isolation Level in the Connection String using the "Microsoft OLE DB Provider for DB2 Version 4.0"?
    We are trying to move from Crystal Reporting that run against a IBM DB2 database on a mainfram to SSRS reporting and we have downloaded the "Microsoft OLE DB Provider for DB2 Version 4.0" and then worked with the DB2 Administrator to create the
    Packages.  We only have access to use the "Read Uncommitted ("MSUR001") package.   We were able to connect and pull data before he removed access to the other packages, but after setting access the Connection keeps trying to use
    the 'Cursor Stability (MSCS001)" package.   How do we change the Default to the "Read Uncommitted ("MSUR001") package???   Since it is keeps defaulting to the the other package
    we can't connect to do it in the T-SQL query, it has to be set at the Connection String level.

    Hi Dannyboy1263,
    According to your description, you want to set the Transaction Isolation Level in Connection String. Right?
    In Reporting Services, the Connection String for OLE DB Connection can only contains Provider, Data Source and Initial Catalog. There's no property for setting Transaction Isolation Level in the Connection String. Based on my knowledge, we can
    only set the Transaction Isolation Level at Query level or set it by using code (C#, VB, Java...) to call the property of Connection. So unfortunately your requirement can't be achieved currently.
    Reference:
    OLE DB Connection Type (SSRS)
    Data Connections, Data Sources, and Connection Strings in Reporting Services
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • How to build a connection string if "Only variable names (i.e.: $variable) may be used as the target of an assignment statement."

    im looping through databases on a server & building  a connection string to each database.
    $SQLConn.ConnectionString = "Server=$SrvName; Database=$DBName; User ID =DBLogin; Password=myPassword;"
    The problem is i get this error:
    Only variable names (i.e.: $variable) may be used as the target of an assignment statement
    I can put the code into an Inlinescript, but then I lose the ability to perform paralellism. Is there any way to construct the connection string in PS Workflow without using an Inlinescript?

    Hi Winston,
    Why not just wrap the InlineScript blocks in a Parallel block, to cause them to execute in parallel?
    For example:
    workflow foo {
    parallel {
    inlinescript {
    start-sleep -Seconds (Get-Random -Minimum 1 -maximum 5)
    "a"
    inlinescript {
    start-sleep -Seconds (Get-Random -Minimum 1 -maximum 5)
    "b"
    Sometimes outputs "a b" and sometimes outputs "b a"

  • How to determine the field size

    I am going to make a multiplatform application that hopefully
    will run on linux and windows 2000.If the os is 2000, then I will use
    vb.net/aspx else I'll use java servlets. I make the connection
    to the web server ( through HTTP) not directly to database server.
    So, the resultset will be stored in the String object. The columns
    will be separated by delimeter. Our problem is how to determine
    the size and type of the fields of mssql,oracle and postgres database
    so that we can include it in the String object.
    Ex.
    String sResultSet=new String();
    ResultSet rs=statement.executeQuery(sSQL);
    while(rs.next()){
    sResultset=sResultSet + rs.getString(field1) + "||" + rs.getString(field2) + "||";
    vertical bars acts as delimeter
    supposedly this is the code:
    sResultset=sResultSet + rs.getString(field1) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||" + rs.getString(field2) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||";
    supposedly this is the code if rs.getFieldType() and rs.getFieldSize() methods are existing
    Anyone can give me an idea how to get the field type and field size of the database?
    thanks in advance

    Yes, but I dont know how to do it.
    Can you give me an example of using it.
    Thanks in advance

  • Can't change the connection string of SSIS package with derived columns?

    We upgraded SQL server 2008 to 2012, copied and converted all SSIS packages from Visual Studio 2008 to 2010.  When I opened a package in VS 2010 and tried to change the connection string, in the local connection managers, if the data source is another
    SSIS package B(.dtsx file) with derived columns, I can't change the connection string of package B. When I opened the file connection manager editor for package B and tried to locate a dtsx file in another location, saved the change, reopened the project.
    Package B still pointed to previous file.  Other packages without derived columns work fine. Any thoughts?

    We are using the package deployment model and refer to other packages in the same project. If
    we changed the path of package B (with derived columns) to "D:\Visual Studio 2010\xxxx", and refer it in package A, in the A's connection manager, the connection string of package B is still its previous location  "D:\Visual
    Studio 2008\xxxx". When we ran the package A in the SQL server agent, the data source is still
     "D:\Visual
    Studio 2008\xxxx", so how can I change it to "D:\Visual
    Studio 2010\xxxx"? Why has the package C (without derived columns) no such problem? thanks.

  • How to determine the maximum allowable length of a filename for Window ?

    Hi all,
    Could I know how to determine the allowable file length (the length of the absolute path) for a file in Window environment?
    Due to some reason, I generated a zip file with a very long filename ( > 170) and put in a folder(the length of the folder path around 90). The length of the absolute path is around 260.
    I used FileOutputStream with the ZipOutputStream to write out the zip file. Everything is working fine while i generating the zip file.
    However, while i try to extract some files from the zip file i just created, i encountered the error
    java.util.zip.ZipException The filename is too long.
    I am using the class ZipFile to extract the files from the zip file like the following
    String absPath = "A very long filepath which exceed 260";
    ZipFile zipF = new ZipFile(absPath);  //<-- here is the root causeIs it possible to pre-determine the maximum allowable filepath length prior i generate the zip file ? This is weird since i got no error while i created the zip file, but have problem in extracting the zip file ......
    Thanks

    Assuming you could determine the max, what would you do about it? I'd say you should just assume it will be successful, but accommodate (handle) the possible exception gracefully. Either way you're going to have to handle it as an "exception", whether you "catch" an actual "Exception" object and deal with that, or manually deal with the length exceeding the max.

  • How to determine the latency time?

    Hi
    How do I determine the latency time?
    I need to connect 3 CAN nodes onto the CAN bus and need to know how to determine the delay(latency) time needed between the transmission of a message from one node and reception at the other,
    The latency time and Bandwidth both play a role in the transmission, right?
    Thanks
    Ekta

    Hi Ekta,
    The software you need if you are using an NI board is NI-CAN, and you can look at the driver download page for the appropriate version for your operating system. I'll suggest you take a look at the example programs that install with that driver to get you started. If you are developing using LabVIEW or LabWindows/CVI, go to Help>>Find Examples>>Hardware Input and Output>>CAN for examples. If you are using Visual Basic or C, go to ...\National Instruments\NI-CAN for examples. I have also attached a LabVIEW example below that shows how to enable self reception.
    If you are using another vendor's CAN board, you will need to install their driver, and see if they have any examples to get you started. I assume the approach for measuring the latency will be similar to what I suggested. Hope this helps. Goodluck!
    Regards,
    Message Edited by _Belle on 04-28-2006 07:42 AM
    Ebele O.
    National Instruments
    Attachments:
    Self_Reception.vi ‏97 KB

  • How to determine the second decimal of currency is equal to 0.

    Hi guys,
    My problem is how to determine the second decimal of currency is equal to 0.
    i.e: 130.23 the second decimal is 3.
    Thx in advance.
    Points will be rewarded.

    Hi Vincent,
    if you want to check the internal currency value, you can not know from the field contents what is the second decimal. Because ABAP currency fields (CURR) are connected to currency key CUKY. For USD or EUR you have two decimals, japanese yen have no decimals where as some arabian pound have three decimals. The default are 2 decimals; all excetions can be found in table TCURX.
    If you WRITE the value it is converted correctly according to the connected currency.
    Just multiply the value with 10 to the power of decimals, e.g. USD value * ( 10 ** 2 ). Then do a MOD: second_decimal_of_currency = ( value * ( 10 ** decimals ) mod 10.
    If result is zero, then the second decimal of currency is equal to 0.
    Regards,
    Clemens

  • Replace the connection string in Excel MDS file

    I had MDS solution from one SQL Server 2012 to another - SQL Server 2014. I have configured Excel file with connection to MDS. How can I safely to replace the connection string in my Excel MDS file and the tables is not broken?
    from Moscow with money

    Hi,
    Excel is just used to manage data and create new entities and attributes. Why not first publish and close your excel before MDS upgraded to 2014? After the upgrade, reconnect new solution in your excel.
    thanks,
    Jerry

  • The Connection String for the Query Log table is automatically encrypted.

    When I try to use the Usage Based Optimization to apply Aggregation Design to my measure group, it shows me the following
    error message.
    The connection string cannot be found. Open Microsoft SQL Server Management Studio and, in the Analysis Server Properties
    page, check the value of the Log\QueryLog\QueryLogConnectionString
    property.
    I encountered this error like two weeks ago.  At that time I just reset the connection string and every things seem
    to be fine.  A week ago, I successfully applied the Usage Based Optimization for one of my cubes.  However when I tried to apply UBO for my other cubes today, I encountered the same issue again!  I believe no one has changed the property of
    the connection string.
    Also if I query the Query Log table, I can see those latest queries made by the users.  I'm sure the queries are still
    logging into this table.
    This is really strange.  Anyone else has encountered the same issue?  Thanks.

    Hello Thomas,
    I encounterd this issue. And I am struggling trying to solve this problem. If you have resolved this issue and I guess you must've, because this post is two years old, could you kindly post how you resolved this issue?
    Thanks in advance
    Best Regards,
    Neeraja

  • Specify wallet location in the connect string

    Hi!
    Can anyone tell me is there any way how an application can use autologin wallet to connect to database without wallet location specified in sqlnet.ora file? For example can you specify a wallet location in the connect string like hostname and a port number?
    The reason I need this is to let our customers use Oracle autologin wallet to connect the application to DB. They would only need to specify the wallet location in the application's configuration file without editing the sqlnet.ora file.
    Thanks in advance for answers or alternative ideas.

    Hi,
    You can go through with the metalink ID
    The Impact of the Sqlnet Settings on Database Security (sqlnet.ora Security Parameters and Wallet Location) [ID 1240824.1]

  • How to create dynamic connection string with variables using ssis.

    Hello,
    Can anyone let me know on how to create dynamic connection string with variables using ssis?
    Any help would be appreciated.

    Hi vinay9738,
    According to your description, you want to connect multiple database from multiple servers using dynamic connection.
    If in this case, we can create a Table in our local database (whatever DB we want) and load all the connection strings.  We can use Execute SQL Task to query all the connection strings and store the result-set in a variable of object type in SSIS package.
    Then use ForEach Loop container to shred the content of the object variable and iterate through each of the connection strings. And then Place an Execute SQL task inside ForEach Loop container with the SQL statements we have to run in all the DB instances. 
    For more details, please refer to the following blog:
    http://sql-developers.blogspot.kr/2010/07/dynamic-database-connection-using-ssis.html
    If there are any other questions, please feel free to let me know.
    Regards,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

Maybe you are looking for