Solved

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

Posted on 2002-07-23
6
217 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
Independent Software Vendors: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

735 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