ODBC Connection Error

harielcom

New Member
Joined
Oct 26, 2009
Messages
6
Hello,

I am modifying the macro in Excel, which was written by my colleague before he quits the company. I have been assigned to continue coding the macro in Excel. The objective of this macro would be " get the required data from a local DB by calling the SQL query and plot the graph based on the data gathered " .

I am quite new to this environment and I am slowly learning the VBA scripts coded by my colleague. When I run the macro, I am getting the Run time error

"Run Time Error 3146 ODBC - call failed". I searched in the internet to resolve this problem, but I couldn't. May be if I am aware of those kind of Excel macros, I could have solved this run time error.

I have pasted below the code

Public FileContents As String 'global variable to contain the SQL query string
Public RowCounter As Integer
Public ColCounter As Integer
Public RowCounter1 As Integer
Public ColCounter1 As Integer
Const FTP_ip = "10.68.20.158"

Private Sub CommandButton1_Click()

Dim strDBName As String
Dim strDBUser As String
Dim strDBPwd As String
Dim strDSNName As String
Dim strConnectionStr As String
Dim strQueryFile_path As String 'filepath of SQL Query file
Dim wrkODBC As Workspace
Dim conDb As Connection
Dim rstTemp As Recordset

strDBName = "tpfdb"
strDBUser = "root"
strDBPwd = "admin"
strDSNName = "tpfdatabase"
strQueryFile_path = ThisWorkbook.Path & "\Queries\"

' Create ODBCDirect Workspace object.
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", strDBUser, strDBPwd, dbUseODBC)

' Open read-only Connection object based on information
' you enter in the ODBC Driver Manager dialog box.
strConnectionStr = "ODBC;DATABASE=" + strDBName + ";UID=" + strDBUser + ";PWD=" + strDBPwd + ";DSN=" + strDSNName
Set conDb = wrkODBC.OpenConnection("localdb", dbDriverComplete, False, strConnectionStr)
Set rstTemp = conDb.OpenRecordset("SET GLOBAL sql_mode='ANSI';", dbOpenDynamic)


I am getting the error while executing the command highlighted above. As I said i am new to this environment, can anyone help me to resolve this?

Also it would be great if anyone can give me some reference/websites that tells about ODBC in Excel.

Many Thanks in Advance!!!!!!!!!!

----------------------------------------------------------

Regards,

Hari.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top