TesT For SQL Connection

by ssi 15. December 2015 15:33
private bool GotConnected2SQL(string sConnectionString)
     {
         bool bRet = false;
         SqlConnection mySQLConnection = new SqlConnection(sConnectionString);
         string SQLStatement = "SELECT control FROM [tbvl_ssi_control]";
         string sSql = string.Format(SQLStatement);
         SqlCommand mySQLCommand = mySQLConnection.CreateCommand();
         try
         {
             mySQLCommand.CommandText = sSql;
             SqlDataAdapter mySQLDataAdapter = new SqlDataAdapter();
             mySQLDataAdapter.SelectCommand = mySQLCommand;
             DataSet myDataSet = new DataSet();
 
             mySQLConnection.Open();
             Console.WriteLine("Retrieving rows from the Query");
             mySQLDataAdapter.Fill(myDataSet, "RECS");
             mySQLConnection.Close();
             DataTable myDataTable = myDataSet.Tables["RECS"];
             bRet = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(string.Format("""SQL Connection Error: {0}", ex.Message), "SQL Connection Status"MessageBoxButtons.OK, MessageBoxIcon.Error);
             bRet = false;
         }
 
         return bRet;
     }

Tags: , ,

CSharp | SQL

Add comment

biuquote
  • Comment
  • Preview
Loading

Calendar

<<  March 2026  >>
MoTuWeThFrSaSu
2324252627281
2345678
9101112131415
16171819202122
23242526272829
303112345

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"Fill the unforgiving minute with sixty seconds worth of distance run."
Rudyard Kipling