Solved

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

Posted on 2002-07-23
6
212 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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