how do i retrieve data from SQLite to VB6? - sqlite

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>>

Related

Apache Ignite ODBC and ADODB Recordset problem fetching data

i try to fetch records from Apache Ignite inmemory database via Microsoft Access 2016 32-Bit and Apache Ignite 32-Bit ODBC-driver with default settings. OS is Windows 10.
Import as a linked table does not work so i tried via ADODB-Class.
Connection.Open and Recordset.Open works and i can see all columns (ID and NAME) of sample table CITY in the Recordset. But when i try to fetch the first record with MoveFirst or MoveNext, i get the error 'specified attribute is not supported'. I tried the same with CursorLocation=adUseClient and the error message changes to 'wrong parameter'. Default Provider is MSDASQL.1. Is this the correct Provider? Any idea how to fetch records with ADODB?
Code
`
Public Sub QueryIgnite()
Dim ADOrs As ADODB.Recordset
Dim ADOcon As ADODB.Connection
Set ADOcon = New ADODB.Connection
ADOcon.ConnectionString = "DSN=Apache-Ignite-DSN"
'ADOcon.CursorLocation = adUseClient
ADOcon.Open
Set ADOrs = New ADODB.Recordset
ADOrs.Open "select * from city", ADOcon, adOpenForwardOnly
ADOrs.MoveNext
Debug.Print ADOrs.Fields("NAME")
ADOrs.Close
ADOcon.Close
End Sub
`
Thank you in advance.
Regards.
Guido Clesius
A ticket on apache.org is created to fix the bug. See https://issues.apache.org/jira/browse/IGNITE-18210

how to connect MYSQL server using ASP.NET?

I want to use MYSQL server with my asp.net application. But i am not able to connect to it. I am getting error that is "ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified " .
My code is:-
System.Data.Odbc.OdbcConnection cn = new System.Data.Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=new_testdb; User=root;Password=abc123#;");
cn.Open();
System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand();
System.Data.Odbc.OdbcDataAdapter adp = null;
DataSet ds = new DataSet();
cmd.Connection = cn;
cmd.CommandText = "Select * from new_table";
adp = new System.Data.Odbc.OdbcDataAdapter(cmd);
adp.Fill(ds, "new_table");
this.GridView1.DataSource = ds;
this.GridView1.DataMember = "new_table";
cn.Close();
Try to download ADO.NET MySql Connector API (managed MySql Data provider) instead of ODBC Driver.
EDIT: Connector/NET Examples
You also may connect to MySQL with dotConnect for MySQL components.
Try to build the connection string with MySqlConnectionStringBuilder class.
This is what you need: http://dev.mysql.com/downloads/connector/net
Enjoy!
Could you please see here My SQL ConnectionString or ConnectionString
Click Left btn on database in server explorer, select properties copy connection string;
2.string c= persistsecurityinfo=True;server=localhost;user id=root;password=admin;database=sam;
MySqlConnection cn = new MySqlConnection(c);
cn.Open();
Response.Write("Connection successful !!");
MySqlDataAdapter Mda = new MySqlDataAdapter("select * from tblName", cn);
DataSet ds = new DataSet();
Mda.Fill(ds, "tblName");
GridView1.DataSource = ds.Tables["tblName"];
GridView1.DataBind();
Make sure that :-
using System.Data;
using MySql.Data.MySqlClient;
imported... :)

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.

ASP.NET Database Connect

Hello when i run my application on server, the connection doesn't open
--> my dataset is still closed
Dim strconnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + "rootPath" + "\" + "VSS_TESTDB.mdb" + "Persist Security Info=False"
Dim objConnection As New OleDbConnection(strconnect)
Dim sql As String = "SELECT VSS_Files.id, VSS_Files.filename,VSS_Files.dateOfCreation,VSSDirs.dir FROM VSS_Files , VSSDirs Where VSS_Files.dir_id = VSSDirs.id;"
Dim cmd As New OleDbCommand(sql, objConnection)
Dim myDataReader As OleDbDataReader
myDataReader = cmd.ExecuteReader()
what can i do?
greetings tyzak
You need to create an OleDbConnection using an OleDbConnectionStringBuilder to connect to the database.
For example:
Dim builder As New OleDbConnectionStringBuilder
builder.Provider = "Microsoft.Jet.OLEDB.4.0"
builder.DataSource = Path.Combine(rootPath, "VSS_TESTDB.mdb")
builder.PersistSecurityInfo = False
Using connection As New OleDbConnection(builder.ToString())
Using command As New OleDbCommand("SELECT VSS_Files.id, VSS_Files.filename,VSS_Files.dateOfCreation,VSSDirs.dir FROM VSS_Files, VSSDirs Where VSS_Files.dir_id = VSSDirs.id;", connection)
connection.Open()
Using reader As OleDbDataReader = command.ExecuteReader()
'Do something
End Using
End Using
EDIT: Your problem is probably that you put quotes around rootPath. The Data Source of your connection string is DataSource=rootPath\VSS_TESTDB.mdb. I assume that you actually want it to have the value of the rootPath variable.
Also, you need to open the connection.
Finally, you should close the connection and the DataReader using the Using statement.
See my updated example.
This question is pretty vague, and it is difficult to properly diagnose from one line of code. Here are a couple of suggestions:
You need to assign this connection string to a connection object.
See http://www.connectionstrings.com/ for the full and proper form for connection strings.

Microsoft ODBC driver for Oracle Syntax error or access violation (-2147217900)

I have a large VB program that connects to Oracle database.
strCn = "Driver={Microsoft ODBC for Oracle};" & _
"SERVER=PSPROD;"
Set Cn = New ADODB.Connection
Cn.ConnectionString = strCn
Cn.CursorLocation = adUseNone
Cn.Open
There are many users of my program so I have a table that contains each user's login name and their access rights to the various tables. I create a recordset of all users when the program is started and then select USERNAME and GRANTED_ROLE from the record set where USERNAME and PASSWORD are found. I use a "Set role 'GRANTED_ROLE' identified by 'password'" statment and Cn.Execute statement to set up the user's access rights. This is all done in a Module.
On a form, I want to call a Stored Procedure that will SELECT, INSERT and UPDATE information into another schema's tables. I am able to call and run the stored procedure when I create a new connection to the database with this code:
Dim cmd5040 As ADODB.Command
Dim conn5040 As ADODB.Connection
Dim param5040 As ADODB.Parameter
Set conn5040 = New ADODB.Connection
conn5040 = "Driver={Microsoft ODBC for Oracle};" & _
"SERVER=PSPROD; UID=XXXXXXX; PWD=XXXXXXXX"
conn5040.Open
Set cmd5040 = New ADODB.Command
With cmd5040
.ActiveConnection = conn5040
.CommandType = adCmdStoredProc
.CommandText = "S4115040_IMPORT_NEWBIDITEMSPES.S4115040_CheckTime"
.Parameters.Append .CreateParameter(, adInteger, adParamInputOutput, 5)
.Parameters.Append .CreateParameter(, adVarChar, adParamInputOutput, 400)
End With
cmd5040(0) = 0
cmd5040(1) = ""
cmd5040.CommandTimeout = 300
cmd5040.Execute
conn5040.Close
However, I get the error message "-2147217900 [Microsoft][ODCB driver for Oracle]Syntax error or access violation" when I attempt to use the same connection ('Cn') when the program first started. My code is:
Dim cmd5040 As ADODB.Command
Dim param5040 As ADODB.Parameter
Set cmd5040 = New ADODB.Command
With cmd5040
.ActiveConnection = Cn
.CommandType = adCmdStoredProc
.CommandText = "S4115040_IMPORT_NEWBIDITEMSPES.S4115040_CheckTime"
.Parameters.Append .CreateParameter(, adInteger, adParamInputOutput, 5)
.Parameters.Append .CreateParameter(, adVarChar, adParamInputOutput, 400)
End With
cmd5040(0) = 0
cmd5040(1) = ""
cmd5040.Execute
I have worked with my DBA. She has given me direct grants and direct execute privliges and I am still get the error message.
What am I doing wrong? Should I be able to use the original connection to run a stored procedure? Or must I create a second connection?
edit: on reviewing your code, I notice that the original connection Cn specifies the driver and the server name whereas the second connection conn5040 specifies the driver, server name, user and password.
Therefore, it may be that the stored procedure you are calling requires a user and password which the original cn connection does not specify
Original answer:
Make sure that the variable cn is still in scope when you try to use it. If it is declared in a module then it should be declared outside of any Sub or Function and, if other modules should be able to access it, it should be declared as Public
Option Explicit
Public cn as ADODB.Connection
Sub foo()
...
Presuming that cn is still in scope, you could examine the State property of the object which cn references to see if the Connection is still open.
If (cn.State = adStateClosed) Then
' we have a problem
...

Resources