Results 1 to 2 of 2

Thread: Check for Error in connecting to SQL server

Threaded View

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Check for Error in connecting to SQL server

    hi! guyz!!! i have a question here..Currently, i have this code below
    Code:
     
                    string sqlConnStr;
                    sqlConnStr = @"Data Source = DAIMOUS\SQLEXPRESS; Initial Catalog=BCMD; User ID=dbuser; Password=dexxa69++";
                    SqlConnection sqlConn = new SqlConnection(sqlConnStr);
                    sqlConn.Open();
    
                    string qryStr = "select Max(id) as u_id from users";
    
                    SqlCommand sqlCmd = new SqlCommand(qryStr, sqlConn);
    
    
                    SqlDataReader reader = sqlCmd.ExecuteReader();
    
                    while (reader.Read())
                    {
                        MessageBox.Show((string)reader["u_id"].ToString ());
                    }
    
                    reader.Close();
                    sqlConn.Close();
    as you can see i dont have a way to check if there's an error like, Server or the Initial Catalog doesn't exist or the username or password is invalid..So is there a way for me to do that? aside from using exceptions. Thanks in advance!!
    Last edited by daimous; Jul 24th, 2006 at 08:20 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width