Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2014, 06:27 PM
donaldadams1951 donaldadams1951 is offline What SQL server and databases are open? Windows XP What SQL server and databases are open? Office 2010 32bit
Advanced Beginner
What SQL server and databases are open?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default What SQL server and databases are open?

Word VBA newbie...

User is running an application that uses MS SQL server. The program can either be using a test database on the back-end or a production database. While in the program they start Word. Word is the way they get data into certain parts of the program since they are using Word to create a report that will be stored in the database.

I have written a .dotm that is in the users Word StartUp folder. I query the database using macros in the macro enabled template.

The issue is that someone could open Word using either the test database or the production database on multiple servers. Since my application queries the database to get certain information I need to know whether they are using the test database or the production database and which server they are located on. I can tell by the name of the database whether they are in the test database or the production database. The test database and production databases could be on the same server or a different server.



Is there a way to use VBA and find out the name of any open SQL databases and the server they are located on? That way I could open the correct database to get the information I need.


Thank you...
Reply With Quote
  #2  
Old 03-02-2014, 05:28 PM
macropod's Avatar
macropod macropod is offline What SQL server and databases are open? Windows 7 32bit What SQL server and databases are open? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

IMHO, you're going about this the wrong way. If the SQL is supposed to work with a particular database, the code should used a fully-qualified database name; not simply work with whatever 'production' database the user has open.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-02-2014, 05:41 PM
donaldadams1951 donaldadams1951 is offline What SQL server and databases are open? Windows XP What SQL server and databases are open? Office 2010 32bit
Advanced Beginner
What SQL server and databases are open?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default I appreciate the concern but...

Is it possible to find the "open" databases and the server on which they reside with VBA? If so how?
Reply With Quote
  #4  
Old 03-02-2014, 05:49 PM
macropod's Avatar
macropod macropod is offline What SQL server and databases are open? Windows 7 32bit What SQL server and databases are open? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To do that, you would have to search all servers for databases, then test whether anyone has them open. This is irrelevant to the question of which database the user running an SQL is using.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-02-2014, 07:40 PM
donaldadams1951 donaldadams1951 is offline What SQL server and databases are open? Windows XP What SQL server and databases are open? Office 2010 32bit
Advanced Beginner
What SQL server and databases are open?
 
Join Date: Dec 2013
Location: San Francisco Bay Area
Posts: 37
donaldadams1951 is on a distinguished road
Default How do I test if the database is open?

There is a only a small number of databases I would have to search. How can I use VBA and tell if the database is open?
Reply With Quote
  #6  
Old 03-02-2014, 07:50 PM
macropod's Avatar
macropod macropod is offline What SQL server and databases are open? Windows 7 32bit What SQL server and databases are open? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See, for example: http://support.microsoft.com/kb/209189

However, given that many databases allow multi-user access, simply know that 'someone' has such a database open isn't of much use, since that doesn't prevent someone else opening the same database; all that gets locked in such instances are the records in use.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
What SQL server and databases are open? Formula to open external file with specific program (like open with) pemartins Excel 16 02-24-2014 11:39 PM
What SQL server and databases are open? Save in SERVER instead. zuzullo Outlook 3 09-08-2011 12:34 AM
unable to open .RTF files in server machine from client machine Naresh_1210 Word 0 03-12-2010 03:26 AM
Exchange Server. Do I need it? SRE Outlook 1 01-11-2010 06:36 PM
Can I use one VERY big server for everything ? RickH Project 0 12-15-2005 08:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft