create pass through query to connect to Sybase
Hi All,
I am a newbie in Access.
Using Access VBA, I am trying to create a Pass Through Query to connect to the Sybase Server so that I can show the user what the recordset looks like. I am having trouble creating the Connect String in the code.
I cannot create a DSN As then it will be machine dependent...in the sense every user who accesses the database(access) has to create a DSN in their own machine.
I created a DSN Less Connection using ADO to Connect to Sybase Server and I am able to read the records as follows:
****************************************
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql, constr, str As String
Set conn = New ADODB.Connection
constr = "Driver={SYBASE ASE ODBC Driver};NA=<x.x.x.x,portnumber>;Uid=USER;Pwd=PASS; "
conn.ConnectionString = constr
conn.Open
sql = "select column1, column2 from Table1";
Set rs = conn.Execute(sql)
While Not rs.EOF
Debug.Print rs.Fields(0) & rs.fields(1)
rs.MoveNext
Wend
' Cleanup
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
****************************************
The Above Code is working when creating a DSN Less Connection using ADO and fetching the recordset.
I want to create a pass though query so that I can open the query and execute it and display data to user.
****************************************
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Dim rs As DAO.Recordset
Dim sql as string
On Error GoTo errBlock
Set db = CurrentDb
sql = "select column1,column2 from table1"
Set qry = db.CreateQueryDef("qryTemp", sql)
qry.Connect = "ODBC;Driver={SYBASE ASE ODBC Driver};NA=<x.x.x.x,portnumber>;UID=user;PWD=pass"
qry.sql = sql
qry.ReturnsRecords = True
Set rs = qry.OpenRecordset(dbOpenSnapshot)
MsgBox rs.RecordCount
DoCmd.OpenQuery "qryTemp"
****************************************
I am getting the error "Invalid connection String" when the qry.connect is executed.
Am I missing something here?
NOTE: I do not(should not) have any DSN created in my machine.
Please advise.
regards
mustang123
|