There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
black screen blue screen boot computer connection crash css dell display driver drivers error excel firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem problems ram router slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
How to get a list of databases in an SQL Server (programatically)


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
wango's Avatar
Member with 74 posts.
 
Join Date: Nov 2001
Location: Silver 'Spring
25-Jan-2002, 04:06 PM #1
How to get a list of databases in an SQL Server (programatically)
How do I programatically get a list of all databases on a known server?
What I need is to make my code as flexible as possible. I suceeded in (1) listing all the availble SQL Servers in the domain; (2) I was able to create a DSN in ODBC dynamically but wit a hardcoded database as in

RETCODE retcode;
LPTSTR szDriver = "SQL Server";

char szAttributesChar[255];

// add datasource name if it exixts
dsn_str = "DSN=" + m_MyProgramaticDSN + "\0";
LPTSTR lpszMyProgramaticDSN = new TCHAR[dsn_str.GetLength()+1];
_tcscpy(lpszMyProgramaticDSN, dsn_str);

server_str = "SERVER=" + m_cmbSQLservername + "\0";
LPTSTR lpszSQLservername = new TCHAR[server_str.GetLength()+1];
_tcscpy(lpszSQLservername, server_str);

LPTSTR lpszDATABASE = "DATABASE=VersaScanMeSQL\0";
LPTSTR lpszDESCRIPTION = "DESCRIPTION=Dynamically created datasetname\0";

...
..

// remove the local datasource name if it exixts
TCHAR szAttributesRemove[1028];
TCHAR* szSubStringRemove = &(szAttributesRemove[0]);
// remove an existing DSN
BOOL bretcode = SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, szDriver,
&(szAttributesRemove[0]) /*szAttributes*/);

As you can see, the database is hardcoded. If I can figureout a way of programtically getting it, I will be okay and that is what I am looking for.

Note that I have not yet connected to the database.
__________________
Wango
elsinaj's Avatar
Member with 40 posts.
 
Join Date: Aug 1999
Location: Grootegast, Groningen, The Netherlands
26-Jan-2002, 05:06 PM #2
I guess you already know this, but the SQL command for this is "show databases". I don't know if this helps anything?

A.J.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:06 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.