Solved

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

Posted on 2002-07-23
6
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

626 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