Monday, March 19, 2012

DMO and Windows Authentication

I'd like to use DMO to browse for databases on our SQL Servers using Windows Authneitication, rather than the SQL Server Authentication with login and password. Is this possible. This is the chuck of code that I've borrowed to do it so far. Can you make the Connection without the user and password?

Thanks,

Howie

Set SQLInstance = New SQLDMO.SQLServer
'Connect to the server by name (from global variable)
SQLInstance.Connect t_Server, t_User, t_Password
'Set the instance to that server ID
SQLSrvrID = SQLInstance.ConnectionID
Set SQLInstance = SQL2000.SQLServers.ItemById(SQLSrvrID)

'Display the available databases in a list box
ListDatabases.Clear
x = 1
For Each DB In SQLInstance.Databases
'Do not add system databases to the list
If Not SQLInstance.Databases(x).SystemObject Then
Me.ListDatabases.AddItem (SQLInstance.Databases(x).name)
End If
x = x + 1
Next

Just as an added question, does anyone know how you might go about exploring for data sources in VB, either with ADO or DMO? These would be the ODBC data source that you would create by:

Control Panel

Administrative Tools

Data Sources(ODBC)

Once in the Data Sources application, you pick a name for the data source, and then locate and define the server and associated database.

Thanks gain for any ideas,

Howie

|||I am using VB6 and I can easily get the username using the API

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

|||' login using windows authentication
SQLInstance.LoginSecure = True
SQLInstance.Connect sServer

You don't need the API above.. thanks to Josh on his website for the answer!

Josh Fruits
http://www.programmers-corner.com

josh@.programmerscorner.com

No comments:

Post a Comment