Re: check database connection/open
- From: zacks@xxxxxxxxxxxxxxxxxxxxxxxx
- Date: 19 Jul 2006 07:05:24 -0700
martin1 wrote:
All, I want to check wether db connection/open or not, if not it will post db
connection error to user in message box
The code is like:
Dim objConnection As New SqlConnection _
("Server=server1; database=db1;user
id=user1;password=whatever")
Dim objDataAdapter As New SqlDataAdapter()
Dim objDataSet
objDataAdapter.SelectCommand = New SqlCommand()
objDataAdapter.SelectCommand.Connection = objConnection
cmdtext = "Select parameter from table1"
objDataAdapter.SelectCommand.CommandText = cmdtext
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objConnection.Open()
objDataAdapter.Fill(objDataSet, "table1")
objConnection.Close()
So if connection problem, it will post error masseage like below
MessageBox.Show("Ths is Database connenction issue", "DataBase Connection
problem")
My question is which code line is used to check if db connection/open or
not, it is objConnection.Open()? if it is, how to check? Thanks
Seems like all you need to do is put the .Fill method call inside of a
Try/Catch block.
.
- Prev by Date: Re: Crystal Reports and Data Tables.
- Next by Date: Argument not specified
- Previous by thread: Create Recordset from a non standard data source
- Next by thread: Re: check database connection/open
- Index(es):
Relevant Pages
|