Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

DSN-less SQL connection from Word Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Reichenbach - 29 Mar 2005 18:49 GMT
Using a Macro in MS Word 2003, I need to call a stored procedure on an SQL
server, with the requirement that the host system does not have a DSN entry
for the server (externally applied constraint).

I have server name, database name, user id, password, etc.

The documentation I have found seems to indicate I need to use a Workspace
object to create a Connection object.

The example below (using DSN) works fine:

   Dim odbc As Workspace
   Dim sql As Connection
   Dim connectStr As String
   
   connectStr = "ODBC;" + _
                "DATABASE=aDataBase;" + _
                "UID=aUser;" + _
                "PWD=aPassword;" + _
                "DSN=TestSql;" + _
                "LOGINTIMEOUT=5;"

   Set odbc = CreateWorkspace("Test Sql", "aUser", "aPassword", dbUseODBC)
   Set sql = odbc.OpenConnection("TestSql", dbDriverCompleteRequired, True, _
                                   connectStr)

' Do work

 sql.Close
 odbc.Close

However, as stated, I have the constraint of not being able to use a DSN. I
have so far not been able to construct a connection string that results in a
successful connection based on server name, etc. instead of DSN.

One connect string of many that I have tried, which does not work is:

   connectStr = "ODBC;" + _
                "Provider=SQL;" + _
                "DATABASE=aDataBase;" + _
                "Server=aServerName;" + _
                "UID=aUser;" + _
                "PWD=aPassword;" + _
                "LOGINTIMEOUT=5;"

The error I get is "ODBC Call Failed", which doesn't tell me much.

Questions:
1) Is this even possible in a Word Macro?
2) If it is possible, are the Workspace / Connection objects the correct
objects to use?
3) Am I just using the wrong connect string contents?
4) ???

Any input will be very appreciated. I am a VERY new VBA user.

Regards,
Jason
Jason Reichenbach - 29 Mar 2005 20:05 GMT
> Using a Macro in MS Word 2003, I need to call a stored procedure on an SQL
> server, with the requirement that the host system does not have a DSN entry
[quoted text clipped - 54 lines]
> Regards,
> Jason

Answers:
1) Yes
2) Yes
3) Yes. Connect string should look something like:

connectStr = "ODBC;DRIVER={SQL Server};" + _
                "SERVER=aServerName;" + _
                "DATABASE=aDatabase;" + _
                "UID=aUser;" + _
                "PWD=aPassword;" + _
                "LOGINTIMEOUT=5;"

4) The Name parameter in the OpenConnection call must be an empty string.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.