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.
Related
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
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
i have the info below from the oracle DBA and want to connect to oracle from a .net application. i just got done installing the oracle tools/ drivers for windows/ .net and now want to get a console app to connect tot he oracle DB and extract data from oracle into SQL server.
another solution would be to have SQL server pull from oracle all the records in the bugs table. i have no clue what the oracle connection string is and have tried to create a system DSN but failed at that prior to turning to the SO gurus...
ORACLE SQL user name is ‘USER_dev’,
password is ‘welcome’.
Connection string is
‘jdbc:mercury:oracle://qct-ds2-p.apps.com:1139;sid=QCTRP1’
i got lucky and found a simple solution that is all in .net and requires nothing more than this syntax by way of a connection string. all the .ora stuff is presented in the connection string and works well.
static void getData()
{
string connectionString = GetConnectionString();
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
//Console.WriteLine("State: {0}", connection.State);
//Console.WriteLine("ConnectionString: {0}", connection.ConnectionString);
OracleCommand command = connection.CreateCommand();
string sql = "SELECT * FROM BUG";
//string sql = "SELECT table_name FROM user_tables";
command.CommandText = sql;
OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//string myField = (string)reader["Project"];
string myField = (string)reader[0];
Console.WriteLine(myField);
}
}
}
static private string GetConnectionString()
{
return "User Id=USER_dev;Password=welcome;Data Source=(DESCRIPTION=" +
"(ADDRESS=(PROTOCOL=TCP)(HOST=111.123.479.24)(PORT=1139))" +
"(CONNECT_DATA=(SID=QCTRP1)));";
}
go into your ORACLE_HOME\network\admin directory. Create a file called tnsnames.ora if it is not there already. Add this into it:
QCTRP1.WORLD =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = qct-ds2-p.apps.com)(PORT = 1139))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = QCTRP1)
)
)
I'm making some assumptions here...
does qct-ds2-p.apps.com resolve?
looks like the DBA set it up the listener on port 1139... default is normally 1521 so you'll need to confirm.
You can then set up a connection string as follows:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:#QCTRP1.WORLD", "dev", "welcome");
now that you have the tnsnames created from #erbsock, you will need to get the .net side of
things working. Oracle has several tutorials available to help you in this matter.
When you install the Oracle ODP (in the link you will see samples as well as the downloads) drivers you will get a directory created in the
%oracle_home%\odp.net\samples\4\DataSet\DSPopulate\src
(this appears to be the same example as located # http://www.oracle.com/technology/sample_code/tech/windows/odpnet/DSPopulate/ViewProducts.cs.html)
as an initial test I would recommend just changing around the id/passwrd/sql/etc and trying it out.
it is not that fundamentally different than using System.Data; but there are a few gotchas and remember that each computer will need to have ODP/Oracle client installed to have them work with the ora connection.
if you have any problems post the exact error msg that is displayed as well as a snippet of your .net code that establishes the connection, does the query, and where it is breaking
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>>
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
...