|
|
Question : connecting to sybase with ado in vba
|
|
Hi, I'm trying to figure out how to connect to sybase with ado. So far I haven't been able to find many good resources online, as most tutorials seem to be for Access databases. I'm using Sybase ASE 12.x, and vba for Excel 2000. I've got the ADO 2.7 library. I know my driver and OLE DB provider. I also know the db name, port, host. But I keep getting error when trying to create and access the recordset.
Dim conn Set conn = CreateObject("ADODB.Connection")
conn.Provider = "the sybase provider" conn.Open "Driver={the driver};" & _ "Database=dbName;" & _ "Srvr=someServer;" & _ "Uid=someID;" & _ "Pwd=pass"
Set rs = CreateObject("ADODB.recordset") rs.Open "select userID from table1, conn"
For Each x In rs.fields MsgBox x Next
I dont think I set up the Open connection correctly, I'm not even sure what kind of string is supposed to go in there (what are all the connection properties that need to be set). Is there even an ADO reference library anywhere online?? Thanks in advance for any insights provided.
|
Answer : connecting to sybase with ado in vba
|
|
Hi,
Follow the below coding, it should work since it's working on my production system :
'database variables Dim dbSAP As New ADODB.Connection Dim rsSAP As New ADODB.Recordset Dim sProc As String Public wsSAP As Worksheet
'FOR CAD_SYSTEM sPass = "passwd" sUserId = "login" sDataSourceName = "database name" ---------------------------------------------------- Sub ConnectToDatabase() 'set logon details: Debug.Print "Connecting to database" On Error GoTo Login_Error If dbSAP.State = 0 Then dbSAP.Open sDataSourceName, sUserId, sPass, 0 End If
Exit Sub Login_Error: MsgBox "Could not connect to the database. Please contact the System Administrator." End 'Application.Quit End Sub
Cheers C.M
|
|
|
|
|