hi,
In my Visual Basic Code, I am connecting to a SQL Server using SQL DMO. Later, I am listing all the databases available in the server. Once the user selects one of the database from the list, the name of the database needs to be assigned to a string. Down the line, I am using SQL Namespace object to connect display the properties of the databse by clicking the Properties button.
The problem I am facing is, Inspite of selecting a database from the list, I am not able to assign it to a string. When I click on the properties button, the properties of the first database in the list is displayed while I want the properties of the database selected to be displayed.
Please suggest.
Code :
If success = True Then
Set oSQLServer = SQL2000.SQLServers.ItemByID(SQLSrvrID)
Dim x As Integer
x = 1
For Each DB In oSQLServer.Databases
If Not oSQLServer.Databases x).SystemObject Then
Me.lstDBs.AddItem (oSQLServer.Databases(x).Name)
End If
x = x + 1
Next
strDatabase = lstDBs.Text
If lstDBs.ListIndex = -1 Then
MsgBox " Please select a Database from the List"
End If
If lstDBs.DataChanged = True Then
strDatabase = lstDBs.Text
End If
Set CurDB = oSQLServer.Databases(strDatabase)
nsArray(0) = oSQLNS.GetRootItem
nsArray(1) = oSQLNS.GetFirstChildItem(nsArray(0), SQLNSOBJECTTYPE_DATABASES)
nsArray(2) = oSQLNS.GetFirstChildItem(nsArray(1), SQLNSOBJECTTYPE_DATABASE, strDatabase)
Set oSQLNSObj = oSQLNS.GetSQLNamespaceObject(nsArray(2))
End If
In my Visual Basic Code, I am connecting to a SQL Server using SQL DMO. Later, I am listing all the databases available in the server. Once the user selects one of the database from the list, the name of the database needs to be assigned to a string. Down the line, I am using SQL Namespace object to connect display the properties of the databse by clicking the Properties button.
The problem I am facing is, Inspite of selecting a database from the list, I am not able to assign it to a string. When I click on the properties button, the properties of the first database in the list is displayed while I want the properties of the database selected to be displayed.
Please suggest.
Code :
If success = True Then
Set oSQLServer = SQL2000.SQLServers.ItemByID(SQLSrvrID)
Dim x As Integer
x = 1
For Each DB In oSQLServer.Databases
If Not oSQLServer.Databases x).SystemObject Then
Me.lstDBs.AddItem (oSQLServer.Databases(x).Name)
End If
x = x + 1
Next
strDatabase = lstDBs.Text
If lstDBs.ListIndex = -1 Then
MsgBox " Please select a Database from the List"
End If
If lstDBs.DataChanged = True Then
strDatabase = lstDBs.Text
End If
Set CurDB = oSQLServer.Databases(strDatabase)
nsArray(0) = oSQLNS.GetRootItem
nsArray(1) = oSQLNS.GetFirstChildItem(nsArray(0), SQLNSOBJECTTYPE_DATABASES)
nsArray(2) = oSQLNS.GetFirstChildItem(nsArray(1), SQLNSOBJECTTYPE_DATABASE, strDatabase)
Set oSQLNSObj = oSQLNS.GetSQLNamespaceObject(nsArray(2))
End If