From: SUKHEN D. <suk...@ya...> - 2016-02-02 05:52:15
|
first i call openconnection method to update some field then i am calling Rename method On Tuesday, February 2, 2016 11:16 AM, SUKHEN DASS <suk...@ya...> wrote: Dear Team, I am facing a problem of connection still in use after clearing the pool and dispose connection objectbut as i close the vb.net application it free the database connection and i can rename the database manually which i want to do at run time Code as belowImports System.DataImports System.Data.SqlClientImports FirebirdSql.Data.FirebirdClient'Imports FirebirdSql.Data.Firebird Imports System.Windows.FormsImports System.IOImports System.TextImports System.Globalization Public myConnection As New FbConnection Public Function OpenConnection(Optional ByVal ByPass_Message As Boolean = False) As Boolean Dim strConString As String = "" Try If myConnection.State = ConnectionState.Closed Then Dim fbConn As New FbConnectionStringBuilder() fbConn.Password = Password fbConn.UserID = UserID fbConn.Pooling = True fbConn.Role = "sysadmin" fbConn.MaxPoolSize = 20 'fbConn.ClientLibrary = "fbclient.dll" If Is_Local_Connection = True Then fbConn.Database = strLocalDatabase Else fbConn.Database = Database_Path End If fbConn.DataSource = DB_Server fbConn.ConnectionLifeTime = 0 fbConn.ConnectionTimeout = 30 fbConn.Charset = "UTF8" fbConn.ServerType = ServerType fbConn.Dialect = 3 If Val(strPort) = 0 Then strPort = 3050 End If fbConn.Port = strPort strConString = fbConn.ToString() myConnection.ConnectionString = fbConn.ToString If fbConn IsNot Nothing Then fbConn = Nothing End If myConnection.Open() End If Return True Catch ex As Exception If ByPass_Message = False Then WriteError(ex.ToString() & vbCrLf & "DB Path :" & Database_Path & "," & vbCrLf & "Local DB:" & strLocalDatabase & vbCrLf & "Conn String:" & Replace(strConString, Password, "")) MessageBox.Show("Path is not valid...Please,check data direcotry setting...!" & vbCrLf & vbCrLf & _ ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Return False End Try End FunctionSub Rename_DBmyConnection.ClearAllPools() FbConnection.ClearPool(myConnection) FbConnection.ClearAllPools() myConnection.Close() 'AppDomain.Unload(AppDomain.CurrentDomain) myConnection.Dispose() myConnection = Nothing IO.File.Replace(txtFile_Path.Text, strCurrent_Database_Path, "D:\Backup\Bkp.fdb")--this line is giving error file in used End Sub |