Solved

Know the USer ID and Initial catalog of SQL Server through VB

Posted on 2002-07-23
6
205 Views
Last Modified: 2008-01-16
How can we know the User Name, Initial Catalog name of SQL server through visual basic 6.0 at runtime.

I want to populate the names of the database users and the initial catalog in the SQL Server database in combobox by passing the SERVER NAME.

0
Comment
Question by:mvarghese
6 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7172066
If you have permissions to the Master database on SQL server you can use Select Name From Master.dbo.SysDatabases to get a list of database names. You can also use:

Select Name,DBName From Master.dbo.SysLogins

Which will give you the user names and their associated default database.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7172212
You can also use SQL-DMO to accomplish this.
0
 

Author Comment

by:mvarghese
ID: 7173437
Dear gencross,

Will you please send me a sample code on how to use the SQL-DMO object as you have said.

Thanks & regards,
Mathew
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Accepted Solution

by:
gencross earned 100 total points
ID: 7174152
This is code I use with SQL 7...

'First reference the Microsoft SQL-DMO Library

'Get a list of available SQL Servers, if you need to
Dim objSQL As SQLDMO.NameList
Set objSQL = SQLDMO.ListAvailableSQLServers
For X = 0 To objSQL.Count - 1
    Debug.Print objSQL(X)
Next

'Connect to server
Dim objSQLServer As SQLDMO.SQLServer
Set objSQLServer = New SQLDMO.SQLServer

'Fill in connection info
sServerName = "Server"
sUserID = "sa"
sPwd = ""

objSQLServer.Connect sServerName, sUserID, sPwd

This is the best I can do right now, but if you look through the object you should be able to find what you are looking for.  Let me know if you need more assistance.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8040409
Hi mvarghese,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept gencross's comment(s) as an answer.

mvarghese, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8095710
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now