Server Connectivity if no server exist
-
Hi All, I am using vb.net 3.5 and Sql Server 2005 There is no problem with connection if Server Name and Database Name Exist. But the Error occurs when Try to connect the server which is not available. then my application goes hang. It is continue Searching. I'm using : Public Sub ConnectConfig(ByVal DSource As String, Optional ByVal Uid As String = "", _ Optional ByVal Pwd As String = "", _ Optional ByVal InCat As String = "", _ Optional ByVal AuthType As String = "") Dim ConnString As String = "" If FrmConfigSetup.cbAuth.SelectedIndex = 0 Then ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Integrated Security=True;Timeout=60;" & "" Else ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Uid=" & Uid & ";Pwd=" & Pwd & ";Timeout=60;" End If SQLConn = New SqlClient.SqlConnection(ConnString) If SQLConn.State = ConnectionState.Open Then SQLConn.Close() SQLConn.Open() Else SQLConn.Open() End If End Sub when it'sTrying to open the connection then goes hang. So, What can I do , please help me.
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
-
Hi All, I am using vb.net 3.5 and Sql Server 2005 There is no problem with connection if Server Name and Database Name Exist. But the Error occurs when Try to connect the server which is not available. then my application goes hang. It is continue Searching. I'm using : Public Sub ConnectConfig(ByVal DSource As String, Optional ByVal Uid As String = "", _ Optional ByVal Pwd As String = "", _ Optional ByVal InCat As String = "", _ Optional ByVal AuthType As String = "") Dim ConnString As String = "" If FrmConfigSetup.cbAuth.SelectedIndex = 0 Then ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Integrated Security=True;Timeout=60;" & "" Else ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Uid=" & Uid & ";Pwd=" & Pwd & ";Timeout=60;" End If SQLConn = New SqlClient.SqlConnection(ConnString) If SQLConn.State = ConnectionState.Open Then SQLConn.Close() SQLConn.Open() Else SQLConn.Open() End If End Sub when it'sTrying to open the connection then goes hang. So, What can I do , please help me.
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
The timeout in the connection string is used for responses to command queries. It does not apply to the connection itself. Your connection attempt can take a few minutes to timeout and throw an exception.
pdnet wrote:
If SQLConn.State = ConnectionState.Open Then SQLConn.Close() SQLConn.Open() Else SQLConn.Open() End If
What the heck is this?? Since you're creating a new connection object all the time, you just need to Open it. A new connection object's state is always going to be Closed.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Hi All, I am using vb.net 3.5 and Sql Server 2005 There is no problem with connection if Server Name and Database Name Exist. But the Error occurs when Try to connect the server which is not available. then my application goes hang. It is continue Searching. I'm using : Public Sub ConnectConfig(ByVal DSource As String, Optional ByVal Uid As String = "", _ Optional ByVal Pwd As String = "", _ Optional ByVal InCat As String = "", _ Optional ByVal AuthType As String = "") Dim ConnString As String = "" If FrmConfigSetup.cbAuth.SelectedIndex = 0 Then ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Integrated Security=True;Timeout=60;" & "" Else ConnString = "Data Source=" & DSource & ";Initial Catalog=" & InCat & ";Uid=" & Uid & ";Pwd=" & Pwd & ";Timeout=60;" End If SQLConn = New SqlClient.SqlConnection(ConnString) If SQLConn.State = ConnectionState.Open Then SQLConn.Close() SQLConn.Open() Else SQLConn.Open() End If End Sub when it'sTrying to open the connection then goes hang. So, What can I do , please help me.
Arindam Banerjee Sr. Software Developer Rance Computer Pvt Ltd. Kolkata (India)
Why don't you ping that server to make sure it is exist before connecting to it?
Like car accidents, most hardware problems are due to driver error. Samir R. Ibrahim