Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
......




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default ODBC connection by udl

Try using the path in the connection string e.g.

.ConnectionString = "File Name=" & ThisWorkbook.Path & _
Application.PathSeparator & _
"edoc.udl;"

--

"Dorothy" wrote in message ...
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
.....

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ODBC connection failed. Jim Moberg Excel Discussion (Misc queries) 0 October 9th 06 03:53 PM
ODBC connection failed. Jim Moberg Excel Discussion (Misc queries) 0 October 9th 06 03:51 PM
ODBC connection failed. Jim Moberg Excel Discussion (Misc queries) 0 October 9th 06 03:48 PM
Broken ODBC Connection dsb Links and Linking in Excel 1 June 12th 06 11:47 PM
ODBC System DSN Connection Mark[_22_] Excel Programming 4 October 21st 03 10:12 AM


All times are GMT +1. The time now is 08:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"