sqlite windows unable to insert - - asp-classic

I'm seeing an error trying to insert new records to q sqlite3 db via Classic ASP, where updates and reads work fine.
ODBC driver does not support the requested properties.
/engine/includes/ajaxed/class_database/database.asp, line 160
which basically boils down to your standard:
connectionString = "DRIVER=SQLite3 ODBC Driver;Database=" & server.mappath("/site.db") & ";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;
set connection = server.createObject("ADODB.connection")
connection.open(connectionString)
set aRS = server.createObject("ADODB.Recordset")
' error raised on next line
aRS.open tablename, connection, adOpenKeyset, adLockPessimistic, adCmdTable
Permissions are correct (basically that file has everyone full control, including IUSR), and I've had to change the db to no journalling due to this problem (Exception Message: Some kind of disk I/O error occurred); reads and updates to existing records are fine.
I am using the current version of the http://www.ch-werner.de/sqliteodbc/ 32-bit odbc driver.
I've tried setting other recordset options like (adOpenKeyset, adLockOptimistic); no luck, same error message. I've attempted a read of the sqliteodbc code to see what the supported properties /are/, but couldn't work it out.

The following code works for me:
Const adOpenKeyset = 1
Const adLockPessimistic = 2
Const adCmdTable = 2
db = "C:\test.db"
connectionString = "DRIVER=SQLite3 ODBC Driver;Database=" & db & _
";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
Set conn = CreateObject("ADODB.Connection")
conn.Open connectionString
Set rs = CreateObject("ADODB.Recordset")
tablename = "a"
rs.Open tablename, conn, adOpenKeyset, adLockPessimistic, adCmdTable
cols = Array("id", "name")
values = Array(3, "baz")
rs.AddNew cols, values
rs.Update
Example:
C:\>sqlite3 test.db "CREATE TABLE a (id integer, name varchar(20));"
C:\>sqlite3 test.db "INSERT INTO a VALUES (1, 'foo');"
C:\>sqlite3 test.db "INSERT INTO a VALUES (2, 'bar');"
C:\>sqlite3 test.db "SELECT * FROM a;"
1|foo
2|bar
C:\>cscript //NoLogo C:\path\to\sample.vbs
C:\>sqlite3 test.db "SELECT * FROM a;"
1|foo
2|bar
3|baz

Related

How to get the total number of records count from a sql ado dB connection in classic asp [duplicate]

I am newbie in VBScript and I've come across with the following problem. I want get data from sql server db and to allow RecordCount properties. Next code get data but RecordCount is disabled. How can I enable this properties
Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=BUG\SQLSERVER2005;Initial Catalog=test;user id ='sa';password='111111'"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand = CreateObject("ADODB.Command" )
myConn.Open DB_CONNECT_STRING
Set myCommand.ActiveConnection = myConn
myCommand.CommandText = ("select * from klienci k where k.indeks = " & oferty(16))
Set klienci = myCommand.Execute
AFAIK you can't change the cursor type when using the Execute method of the Command object, and you can't change the cursor type after you retrieved the recordset. Something like this might work, though:
Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=BUG\SQLSERVER2005;Initial Catalog=test;user id ='sa';password='111111'"
Set myConn = CreateObject("ADODB.Connection")
myConn.Open DB_CONNECT_STRING
query = "select * from klienci k where k.indeks = " & oferty(16)
Set klienci = CreateObject("ADODB.Recordset")
klienci.CursorLocation = 3 'adUseClient
klienci.CursorType = 3 'adOpenStatic
klienci.LockType = 1 'adLockReadOnly
klienci.Open query, myConn
I don't think this is a VBScript issue- I think it is an ADO issue.
I think you are using a default forward-only cursor which won't work with recordcount.
I think you should stick a cursortype=adOpenStatic in there but I'm having a little trouble determining if you are specifying a recordset object - klienci?
If so try
klienci.cursortype=adOpenStatic

Parameterizing sql in asp

I'm not terribly familiar with asp, but I have one project with a page of it.
<%
'declare the variables
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL
Dim userName
userName = Request.Form("userName")
'define the connection string, specify database driver
ConnString="JJJJJ"//connection information
'declare the SQL statement that will query the database
SQL = "SELECT info AS Lunch, "
SQL = SQL & "FROM dbo.AgentActivityLog WHERE UserId = '" & userName & "'
'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'Open the connection to the database
Connection.Open ConnString
'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection
'first of all determine whether there are any records
If Recordset.EOF Then
Response.Write("No records returned.")
Else
'process record
Next
Recordset.MoveNext
Loop
End If
'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
How do I parameterize the username? I have no way to debug, no knowledge of how this language works, so whatever I tried failed and I have no idea why.
I would suggest you look at the Answer on following link as it will fill in the answers you seek:
VBA, ADO.Connection and query parameters
From the code provided critical missing piece is the ADODB.Command for the SQL to actually be run and to add the parameter the query you would :
Set Param = Command.CreateParameter("#userid",adVarChar,adParamInput)
Param.Value = userName
Command.Paramters.Append Param

How to import Access data to SQLite with ODBC into an existing table, not a new one?

I want to import data (not structure) from Access to SQLite via ODBC
and it works, but there is one point that is annoying:
I don't want to create a new table automatically - I want to import data into my existing table and I get the following error:
ODBC--call failed
table "x" already exists(1)(#1)
I want to find a way to avoid creating new table in sqlite.
I have also tried another solution for importing my data from Access to SQLite via csv. However, my encoding is utf-8 but it shows data as question marks!
There are many ways to move data around using Access.
When appending data to ODBC tables, I recommend the following steps:
Create a linked table to the ODBC table you want to import to in Access using Import -> ODBC database
Use an append query to move the data from the local table to the ODBC table
(optional) Remove the linked table.
Alternatively, Access can directly run append queries to ODBC data sources without creating linked tables, but this requires some SQL knowledge. Syntax is the following:
INSERT INTO [ODBC;MyDSNOrConnectionString].[MyRemoteTable] (Field1, Field2, FieldN)
SELECT Field1, Field2, FieldN
FROM MyLocalTable
There is another way of exporting Access table records into an exisitng ODBC table with Adobe connection, if the tables on both side have the same name and the same structure and if the table structure is stored in a system table.
Dim Str_Sql As String
Dim Conn As New ADODB.Connection
Dim myDSN As String
Dim UserName As String
Dim Password As String
Dim Rs_Tabl As DAO.Recordset
Dim Rs_TablStru As DAO.Recordset
myDSN = ...
UserName = ...
Password = ...
Conn.Open "dsn=" & myDSN & ";uid=" & UserName & ";pwd=" & Password
Set cmd = CreateObject("ADODB.Command")
Set cmd.ActiveConnection = Conn
Set Rs_Tabl = CurrentDb.OpenRecordset(TablName)
Set Rs_TablStru = CurrentDb.OpenRecordset("select * from Systable where TableName=TableName order by ColumnOrder")
Str_Sql = "truncate table TableName"
Conn.Execute (Str_Sql)
Str_Sql = "insert into TableName values ('"
Do Until Rs_Tabl.EOF
Str_Sql = "insert into TableName values ('"
Rs_TablStru.MoveFirst
Do Until Rs_TablStru.EOF
Str_Sql = Str_Sql & Rs_Tabl.Fields(Rs_TablStru.Fields("AAA")) & "','"
Rs_TablStru.MoveNext
Loop
Str_Sql = Mid(Str_Sql, 1, Len(Str_Sql) - 2) & ")"
Debug.Print Str_Sql
Conn.Execute (Str_Sql)
Rs_Tabl.MoveNext
Loop
Rs_Tabl.Close
Rs_TablStru.Close
Set Rs_Tabl = Nothing
Set Rs_TablStru = Nothing
Conn.Close
*AAA:A column from system table that stores column names from all tables.

Ado connection to SQL Server Compact Edition 4.0

I want to connect to SQL Server Compact Edition 4.0 from an old asp-classic site but i always get the error:
"Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. "
I tried
sCon = "Data Source=c:\temp\sqlcompact.sdf;Encrypt Database=True;Password=testtest;Persist Security Info=False;"
and
Update:
Error: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done
sCon = "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source=c:\temp\sqlcompact.sdf;Password=testtest;"
without any success.
Is it generally possible to connect to SQL Server CE 4.0 from ADO?
Update:
Example Code
Open Connection:
dim sCon
dim gCON : set gCON=CreateObject ("ADODB.Connection")
sCon = "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source=c:\temp\sqlcompact.sdf;Pwd=testtest;"
gCon.ConnectionString = sCon
gCon.Open
gCon.Close
Yes, you can connect to SQL CE 4 via ADO.
Set Cnxn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
strCnxn = "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;" & _
"Data Source=C:\nw40.sdf;"
Cnxn.Open strCnxn
cmd.ActiveConnection = Cnxn
cmd.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"
While Not pRS.EOF
WScript.Echo pRS(0)
pRS.MoveNext
wend
For password protected files, use:
strCnxn = "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;" &
_ "Data Source=C:\nw40.sdf;ssce:database password=secret"
Try with the the following provider instead, saw somewhere it's being used with success:
sCon = "Provider=Microsoft.SqlServer.Mobile.OleDb.3.0;Data Source=c:\temp\sqlcompact.sdf;Password=testtest;"
If no luck, can you create System DSN successfully? If so, create one then use it in the ASP code.

how do i retrieve data from SQLite to VB6?

i am using SQLite3 ODBC Driver as my connection string,
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER=SQLite3 ODBC Driver;Database=test.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
conn.Open
rs.Open "select * from Artists", conn, adOpenDynamic, adLockOptimistic
MsgBox rs.Fields(0)
Refer here for the connection string properties:
http://www.connectionstrings.com/sqlite
You should also specify the version (3 or 2).
Edit: try to remove: LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0
And add the version: version=3
If it works, try to add a property at a time until it won't work anymore, to identify the broken property.
These are available connect string options for SQLite3 ODBC Driver
Description=
Database=<<file_name>
Timeout=
StepAPI=0
SyncPragma=
NoTXN=0
ShortNames=0
LongNames=0
NoCreat=0
NoWCHAR=0
FKSupport=0
LoadExt=
I just created a system DSN and looked in registry at HKLM\SOFTWARE\ODBC\ODBC.INI\<<my_dsn_here>>

Resources