View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dorothy[_4_] Dorothy[_4_] is offline
external usenet poster
 
Posts: 1
Default ODBC connection by udl

I am working on Excel Macro that run query and retrieve
data from SQL server. I made a udl file in the same folder
as the Excel file and it can successfully connect to the
server.
The excel macro code as below. Can someone give me some
hints why it cannot connect through udl? Or is there any
way to solve? Thanks a lot.



Dim rstRecordset As ADODB.Recordset
Dim cn As ADODB.Connection

Set cn = New ADODB.Connection
With cn
.ConnectionString = "File Name=edoc.udl;"
.CursorLocation = adUseServer
.Open
End With

Set rstRecordset = New ADODB.Recordset
With rstRecordset
.CursorType = adOpenStatic
.LockType = adLockReadOnly
End With
......