How do you handle a DataSet not being returned from the database if the server is off or unavailable?
For instance, you have some code that requests a DataSet from SS2K like so:How do you guys catch a situation where the db is not available? Right now, this code will error out on the row count line saying "Object reference not set to an instance of an object".VB Code:
Dim dsUSA As DataSet = MakeConnection("sql statement", "jimmy") Dim iRecCount As Integer = dsUSA.Tables(DS_ENTRY).Rows.Count Public Function MakeConnection(ByVal sSQL As String, ByVal sTempDataSetName As String) As DataSet Dim DS As DataSet = New DataSet Try 'Creates connection to database and gets a dataset of values Dim Conn As SqlConnection = New SqlConnection(SS2K) Dim Cmd As SqlDataAdapter = New SqlDataAdapter(sSQL, Conn) 'Sends back a dataset object full of data from the SQL statement Cmd.Fill(DS, sTempDataSetName) Catch Exp As Exception ' End Try Return DS End Function




Reply With Quote