Private Sub btnRefreshConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefreshConnect.Click
Dim dbList As New Collection
Me.ddlDatabaseNames.Items.Clear()
Dim databaseName As String
Try
Me.Cursor = Cursors.WaitCursor 'Changing the Cursor to Waititng State
If Not DBUtil.ServerName = "" Then
dbList = DBUtil.GetDatabases()
If Not dbList Is Nothing Then
For Each databaseName In dbList 'For Addig the Database Names To DropdownList
Me.ddlDatabaseNames.Items.Add(databaseName)
Next
End If
Dim strLastUsedDatabase As String = DBUtil.ReadValuesFromRegistry(Microsoft.Win32.Registry.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "LastUsedDatabase")
If (Not strLastUsedDatabase = "") Then
Me.ddlDatabaseNames.SelectedIndex = Me.ddlDatabaseNames.FindString(strLastUsedDatabase)
End If
End If
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "Server", Me.txtServer.Text)
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "LastUsedDatabase", Me.ddlDatabaseNames.Text)
If (chkTrustConnection.Checked = True) Then
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerUserName", "")
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerPassword", "")
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "TrustedConnection", "true")
Else
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerUserName", Me.txtServerUsername.Text)
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerPassword", Me.txtServerPassword.Text)
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "TrustedConnection", "false")
End If
Catch ex As Exception
If (ex.Message = "Invalid Login or Password") Then
MessageBox.Show("Invalid Login or Password")
Return
End If
' ErrorLog.LogError(ex)
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
----------------------------
Public Shared Function GetDatabases() As Collection 'ByVal strSQLServerName As String, ByVal blnTrustedConnection As Boolean, Optional ByVal strSQLUsername As String = "", Optional ByVal strSQLPassword As String = "") As Collection
'Dim dbServer As New SQLDMO.SQLServer
Dim dbServer As Server
Dim objSvrConn As ServerConnection
DBUtil.DefaultTableName = System.Configuration.ConfigurationManager.AppSettings.Item("VersionTableName") 'commented by Sandeep on 15sept here connection.xml file is used instead of app.config
'DBUtil.DefaultTableName = Helper.GetConnectionDetails.Rows(0)("VersionTableName")
Dim db As Microsoft.SqlServer.Management.Smo.Database
Try
objSvrConn = New ServerConnection()
'dbServer.LoginSecure = UseTrustedConnection
objSvrConn.LoginSecure = False
objSvrConn.ServerInstance = ServerName
objSvrConn.Login = ServerUserName
objSvrConn.Password = ServerPassword
Try
dbServer = New Server(objSvrConn)
'dbServer.Connect(ServerName, ServerUserName, ServerPassword)
Catch dbEx As Exception
Throw New Exception("Invalid Login or Password " & dbEx.Message)
End Try
Dim dbTable As Microsoft.SqlServer.Management.Smo.Table
Dim dbList As New Collection
'retrieving all the Databases from the Database Server which have our defaultTableName
For Each db In dbServer.Databases
'If Not db.SystemObject And db.Status = SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Normal Then
Try
For Each dbTable In db.Tables
' If dbTable.Name = DBUtil.DefaultTableName Then
dbList.Add(db.Name)
Exit For
' End If
Next dbTable
Catch ex As System.Runtime.InteropServices.COMException
End Try
'End If
Next db
Return dbList
Catch sqlEx As System.Runtime.InteropServices.COMException
Catch ex As System.Exception
Throw ex
Finally
'dbServer.DisConnect()
End Try
End Function
==================
Dim dbList As New Collection
Me.ddlDatabaseNames.Items.Clear()
Dim databaseName As String
Try
Me.Cursor = Cursors.WaitCursor 'Changing the Cursor to Waititng State
If Not DBUtil.ServerName = "" Then
dbList = DBUtil.GetDatabases()
If Not dbList Is Nothing Then
For Each databaseName In dbList 'For Addig the Database Names To DropdownList
Me.ddlDatabaseNames.Items.Add(databaseName)
Next
End If
Dim strLastUsedDatabase As String = DBUtil.ReadValuesFromRegistry(Microsoft.Win32.Registry.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "LastUsedDatabase")
If (Not strLastUsedDatabase = "") Then
Me.ddlDatabaseNames.SelectedIndex = Me.ddlDatabaseNames.FindString(strLastUsedDatabase)
End If
End If
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "Server", Me.txtServer.Text)
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "LastUsedDatabase", Me.ddlDatabaseNames.Text)
If (chkTrustConnection.Checked = True) Then
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerUserName", "")
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerPassword", "")
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "TrustedConnection", "true")
Else
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerUserName", Me.txtServerUsername.Text)
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "ServerPassword", Me.txtServerPassword.Text)
DBUtil.WriteValuesToRegistry(Microsoft.Win32.RegistryHive.CurrentUser, "SOFTWARE\FocalTechnology\DBVersionUpgrade", "TrustedConnection", "false")
End If
Catch ex As Exception
If (ex.Message = "Invalid Login or Password") Then
MessageBox.Show("Invalid Login or Password")
Return
End If
' ErrorLog.LogError(ex)
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
----------------------------
Public Shared Function GetDatabases() As Collection 'ByVal strSQLServerName As String, ByVal blnTrustedConnection As Boolean, Optional ByVal strSQLUsername As String = "", Optional ByVal strSQLPassword As String = "") As Collection
'Dim dbServer As New SQLDMO.SQLServer
Dim dbServer As Server
Dim objSvrConn As ServerConnection
DBUtil.DefaultTableName = System.Configuration.ConfigurationManager.AppSettings.Item("VersionTableName") 'commented by Sandeep on 15sept here connection.xml file is used instead of app.config
'DBUtil.DefaultTableName = Helper.GetConnectionDetails.Rows(0)("VersionTableName")
Dim db As Microsoft.SqlServer.Management.Smo.Database
Try
objSvrConn = New ServerConnection()
'dbServer.LoginSecure = UseTrustedConnection
objSvrConn.LoginSecure = False
objSvrConn.ServerInstance = ServerName
objSvrConn.Login = ServerUserName
objSvrConn.Password = ServerPassword
Try
dbServer = New Server(objSvrConn)
'dbServer.Connect(ServerName, ServerUserName, ServerPassword)
Catch dbEx As Exception
Throw New Exception("Invalid Login or Password " & dbEx.Message)
End Try
Dim dbTable As Microsoft.SqlServer.Management.Smo.Table
Dim dbList As New Collection
'retrieving all the Databases from the Database Server which have our defaultTableName
For Each db In dbServer.Databases
'If Not db.SystemObject And db.Status = SQLDMO_DBSTATUS_TYPE.SQLDMODBStat_Normal Then
Try
For Each dbTable In db.Tables
' If dbTable.Name = DBUtil.DefaultTableName Then
dbList.Add(db.Name)
Exit For
' End If
Next dbTable
Catch ex As System.Runtime.InteropServices.COMException
End Try
'End If
Next db
Return dbList
Catch sqlEx As System.Runtime.InteropServices.COMException
Catch ex As System.Exception
Throw ex
Finally
'dbServer.DisConnect()
End Try
End Function
==================
No comments:
Post a Comment