The below code is producing an error by saying {"Keyword not supported: 'provider'."} I can't update my database table.
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Comp-296\Project1\Project1\Game_time.mdb"
I assume you are using the SqlClient library , try OleDB instead:
Imports System.Data.OleDb
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "yourconstring"
Related
With some vb.net code I try to retrieve data from an Oracle database (simplified example):
strQuery = "Select 2.3, 2.3/1, 2.3/3.1 From Owner.TableName Where ROWNUM < 10"
Dim da As OracleDataAdapter
da = New OracleDataAdapter(strQuery, ConnectionString)
da.Fill(GetData)
This results in an "Specified cast is invalid" error.
The 2.3/3.1 is the problem.
I learned from "Specified cast is not valid" when populating DataTable from OracleDataAdapter.Fill() that Oracle works with a higher precision than dot net can handle and that I should use SuppressGetDecimalInvalidCastException in the OracleDataAdapter. But I don't know how to code it in VB.net. Can anyone help me?
Automatic translation from the C# code did not work.
The C# code itself did not work for me (probably due to the fact that I don't know how to handle the async stuff) and if I simplify it to
string queryString = "Select 2.3, 3.1 From owner.table";
string connectionString = "Data Source=Data.plant.be/database;User ID=****;Password=****";
var table = new DataTable();
var connection = new OracleConnection(connectionString);
var command = new OracleCommand(queryString, connection);
var adapter = new OracleDataAdapter(command) {
SuppressGetDecimalInvalidCastException = true
};
adapter.Fill(table);
I get error CS0117: OracleDataAdaptor does not contain a definition for SuppressGetDecimalInvalidCastException.
Extra info:
As proposed by #Andrew-Morton - thank you Andrew - I wrote:
Dim table = New DataTable()
Dim connection = New OracleConnection(ConnectionString)
Dim cmd = New OracleCommand(strQuery, connection)
Dim adapter = New OracleDataAdapter(cmd) With {.SuppressGetDecimalInvalidCastException = True}
adapter.Fill(GetData)
But I get BC30456: SuppressGetDecimalInvalidCastException is not a member of 'OracleDataAdapter'.
Remark: I have version 19.6 of Oracle.ManagedDataAccess.
I could not install package 'Oracle.ManagedDataAccess 21.9.0'. I Get: You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I want to import data from Oracle database to Excel using VBA. I've tried several options I found in here or in the official manual but none of them seem to work for me - I always get the same unspecified runtime error on line with
rs.Open strSQL1, con
or
Set rs = con.Execute(strSQL1)
depending on which one of these two methods I use obviously. Here is the whole code:
Sub data_distribution()
'Setting up the database connection
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL1, strInput, strCon As String
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
strCon = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=XXX)(PORT=XXX))" & _
"(CONNECT_DATA=(SERVICE_NAME=XXX))); uid=XXX; pwd=XXX;"
'--- Open the above connection string.
con.ConnectionString = strCon
con.Open
'con.Open strCon
'--- Now connection is open and you can use queries to execute them.
'--- It will be open till you close the connection
'Definition of parameter
strInput = InputBox("Insert car_id")
strSQL1 = "select * from car where car_id = " & strInput & ""
'Executing the query
'rs.activeconnection = con
'rs.Open strSQL1, con
Set rs = con.Execute(strSQL1)
rs.Open strSQL1, con
Worksheets("Data").Range("A2").CopyFromRecordset rs
'Closing connection
rs.Close
con.Close
Set con = Nothing
Set rs = Nothing
I was thinking it might be an issue of connecting to the database but if I import/query data manual, it works just fine. For example using this manual
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
I had to download and configure ODAC for Windows from Oracle site to make it work. I use tsnames.ora to set the path. Wasn't sure if I configured it right but it works so I guess there isn't a problem with the connection in vba either, or is it? (The variables are, of course, set to real values, not "XXX")
The query itself is correct and returns valid results from the database. Libraries necessary to use ADOBD are linked as well. (Microsoft ActiveX Data Objects 2.0 Library)
There is an existing question with the same error but it's unresolved:
Unspecified run time error while executing vba script
I'm guessing it's station/interface specific (I use Excel 2010, SQL developer).
Even though it's been some time I asked the question, here, it's still unresolved so I will answer myself.
The problem was in the car table where one of the attributes was type CLOB (CHARACTER LARGE OBJECT) with lenght over 2000 characters. Excel was unable to cope with that type and the query caused the unspecified error. If I listed all attributes but this one, it all went well.
I am trying to connect my vb 6.0 application to the database , so i have declared my data base as Dim dbStu as Database,but while compiling it is giving me error user defined type not defined , i found on another thread that , i need to add the Microsoft Active x Data Objects 2.8 for xp.I have done that too.so now my doubt is am i doing this correct ? should i have to declare those data base variable in form only ?.Or is there anything that is causing the error
you must add a reference to Microsoft Active x Data Objects 2.8 or later
then declare an ADODB.Connection and open it with proper ConnectionString value that specify your database path and if it has a password a password value
and then you can use this connection object to get data from your database or insert data to it
public cnn As ADODB.Connection
public rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open "PROVIDER=MSDataShape;DATA PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= DatabasePath\DatabaseName.mdb ;Jet OLEDB:Database " 'Password= DataBasePassword ;"
Set rs = New ADODB.Recordset
rs.Open "Select * from FZONE ", cnn, adOpenDynamic, adLockOptimistic
We have very old VB6 applications connecting to a Sybase database. Today they are running fine using the Open Client 12 drivers via ODBC connecting to a Sybase ASE 15 servers.
There is a plan on upgrading to the OpenClient 15 drivers and with that version I'm getting this error:
Run-time error '-2147467259(80004005)'
Transaction cannot have multiple recordsets with this cursor type.
Change the cursor type, commit the transaction, or close one of the recordsets.
As I understand searching the internet, the problem is in the Cursors.
In the old drivers in the ODBC configuration manager there was a Performance Tab and we have the Select Method in cursor, but with the new drivers this tab is gone and all we got about cursors is a section in the General tab named Cursor Behavior, in there we have the option Use Cursors checked.
Here is a little code snippet where I can reproduce the problem. All help is appreciated.
Dim conObj As ADODB.Connection
Dim objRs As ADODB.Recordset
Dim objRs2 As ADODB.Recordset
Set conObj = New ADODB.Connection
conObj.ConnectionTimeout = 10
conObj.CommandTimeout = 5
conObj.Provider = "MSDASQL"
conObj.Open "DSN=cdbur32;UID=***;PWD=***;Database=dbsait;WSID=Test;APP=Test"
conObj.CursorLocation = adUseClient
conObj.BeginTrans
Set objRs = New ADODB.Recordset
Set objRs.ActiveConnection = conObj
objRs.Source = "select id_estatus_aplicacion from dbo.cat_sait_estatus_aplicaciones"
objRs.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
objRs.LockType = ADODB.LockTypeEnum.adLockReadOnly
objRs.Open
objRs.MoveNext
Debug.Print objRs("id_estatus_aplicacion")
Set objRs2 = New ADODB.Recordset
Set objRs2.ActiveConnection = conObj
objRs2.Source = "select * from dbo.cat_sait_estatus_aplicaciones"
objRs2.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
objRs2.LockType = ADODB.LockTypeEnum.adLockReadOnly
objRs2.Open 'error here
objRs.MoveNext
Debug.Print objRs("id_estatus_aplicacion")
conObj.RollbackTrans
objRs.Close
objRs2.Close
Set conObj = Nothing
Does changing lines
objRs.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
and
objRs2.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
help?
in the end the Sybase guys send us a new drivers and that fixed the problem
I'm having difficulty using the Update function on a RecordSet object while using the DBISAM 4 ODBC driver. Here is what my code looks like.
dtmNewDate = DateSerial(1997, 2, 3)
MsgBox(dtmNewDate)
'Create connection object & connection string
Set AConnection = CreateObject("ADODB.Connection")
strConnection = "Driver={DBISAM 4 ODBC Driver}; CatalogName=S:\RAPID\Z998\2008; ReadOnly=False"
Aconnection.Mode = adModeReadWrite
AConnection.Open strConnection
'create SQL statement to be run in order to populate the recordset
strSQLEmployeeBDate = "SELECT * FROM Z998EMPL WHERE state = 'NY'"
'Create Recordset object
Set rsRecSet = CreateObject("ADODB.Recordset")
rsRecSet.LockType = 2
rsRecSet.Open strSQLEmployeeBDate, AConnection
While Not rsRecSet.EOF
rsRecSet.Fields("BIRTHDATE").value = dtmNewDate
rsRecSet.Update
rsRecSet.MoveNext
Wend
When I try to execute this code I receive the following error:
"DBISAM Engine Error #11949 SQL Parsing error- Expected ( but instead found = in UPDATE SQL statement at line 1, column 336"
I can't figure out what is causing this error. Does anyone have any ideas as to what is causing it?
DBISAM error messages Check the field name.