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

Calendar

<<  May 2024  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

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