user1876635
user1876635

Reputation: 21

How to connect an sqlite database in javascript ASP

Hi I've got this code which uses Access to open/store data in database. I need to convert this to use SQLite. However I'm finding it difficult to find the appropriate connection string. How should I go about doing this? Thanks

var dbaseConnection = Server.CreateObject("ADODB.Connection");          
var pathToDbase = Server.MapPath("contacts.mdb");            
var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + pathToDbase;
dbaseConnection.Open(connectionString);  

This is just test code but I am trying to just read and display information from an sqlite database.

    <table>
        <tr><th>Name</th><th>Surname</th></tr>

        <%

              var dbaseConnection = Server.CreateObject("ADODB.Connection");


              var connectionString = "DRIVER=SQLite3 ODBC Driver; Database= path to test.db; LongNames=0; Timeout=1000; NoTXN=0; SyncPragma=NORMAL; StepAPI=0;";
              dbaseConnection.Open(connectionString);

              var query = "Select * from test order by name asc";
              var recordSet = dbaseConnection.Execute(query);


              while (!recordSet.Eof) {
                 Response.write("<tr><td>" + recordSet("name") + '</td><td>' + recordSet("surname") + "</td></tr>");
                 recordSet.moveNext();
              }

              recordSet.Close();
              dbaseConnection.Close();

        %>

    </table>
</body>

I am now getting this error Microsoft OLE DB Provider for ODBC Drivers error '80004005' connect failed. Any thoughts? I've activated 32 bit apps in IIS.

Upvotes: 2

Views: 1059

Answers (1)

Ali Sheikhpour
Ali Sheikhpour

Reputation: 11121

DRIVER=SQLite3 ODBC Driver;Database=c:\mydb.db;LongNames=0;Timeout=1000;NoTXN=0; SyncPragma=NORMAL;StepAPI=0;

Reference: https://www.connectionstrings.com/sqlite/

Upvotes: 1

Related Questions