This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Connection String class | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Data.OleDb; | |
using System.Data.Odbc; | |
namespace killercodes_in.dbConnect | |
{ | |
public static class EConnection | |
{ | |
/// <summary> | |
/// Checks the connection and returns true if connection is sucessful | |
/// </summary> | |
/// <param name="sqlc">Sql Connection Object</param> | |
/// <param name="ShowMsgOnError">Set True to show message on error</param> | |
/// <returns>True if OK</returns> | |
public static bool Error(this SqlConnection sqlc, bool ErrorReport) | |
{ | |
try | |
{ | |
sqlc.Open(); | |
sqlc.Close(); | |
return true; | |
} | |
catch (Exception se) | |
{ | |
if (ErrorReport) | |
{ | |
System.Windows.Forms.MessageBox.Show( | |
se.Message, | |
"Error @ " + se.Source, | |
System.Windows.Forms.MessageBoxButtons.OK, | |
System.Windows.Forms.MessageBoxIcon.Stop); | |
} | |
return false; | |
} | |
} | |
/// <summary> | |
/// Checks the connection and returns true if connection is sucessful | |
/// </summary> | |
/// <param name="olec">Oledb Connection Object</param> | |
/// <param name="ShowMsgOnError">Set true to show message on error</param> | |
/// <returns>True is OK</returns> | |
public static bool Error(this OleDbConnection olec, bool ErrorReport) | |
{ | |
try | |
{ | |
olec.Open(); | |
olec.Close(); | |
return true; | |
} | |
catch (Exception se) | |
{ | |
if (ErrorReport) | |
{ | |
System.Windows.Forms.MessageBox.Show( | |
se.Message, | |
"Error @ " + se.Source, | |
System.Windows.Forms.MessageBoxButtons.OK, | |
System.Windows.Forms.MessageBoxIcon.Stop); | |
} | |
return false; | |
} | |
} | |
/// <summary> | |
/// Checks the connection and returns true if connection is sucessful | |
/// </summary> | |
/// <param name="odbcc">Odbc Connection object</param> | |
/// <param name="ShowMsgOnError">True to show msg on error false for not</param> | |
/// <returns>True if OK</returns> | |
public static bool Error(this OdbcConnection odbcc, bool ErrorReport) | |
{ | |
try | |
{ | |
odbcc.Open(); | |
odbcc.Close(); | |
return true; | |
} | |
catch (Exception se) | |
{ | |
if (ErrorReport) | |
{ | |
System.Windows.Forms.MessageBox.Show( | |
se.Message, | |
"Error @ " + se.Source, | |
System.Windows.Forms.MessageBoxButtons.OK, | |
System.Windows.Forms.MessageBoxIcon.Stop); | |
} | |
return false; | |
} | |
} | |
//========================================= | |
/// <summary> | |
/// Creates a Trusted connection string with SqlConnection | |
/// </summary> | |
/// <param name="sqc">Sql connection Object</param> | |
/// <param name="Data_Source">IP Address or Named Pipe</param> | |
/// <param name="Init_Catalog">Database Name</param> | |
public static void CS_SqlTrusted(this SqlConnection sqc, string Data_Source, string Init_Catalog) | |
{ | |
sqc.ConnectionString = "Data Source=" + Data_Source + | |
";Initial Catalog=" + Init_Catalog + | |
";Integrated Security=SSPI;"; | |
} | |
/// <summary> | |
/// Creates a Trusted connection string with SqlConnection | |
/// </summary> | |
/// <param name="sqc">Sql connection Object</param> | |
/// <param name="Server">IP Address</param> | |
/// <param name="Database">Database Name</param> | |
/// <param name="Trusted_Connection">True to create trusted</param> | |
public static void CS_SqlTrusted(this SqlConnection sqc, string Server, string Database, bool Trusted_Connection) | |
{ | |
sqc.ConnectionString = "Server=" + Server + | |
";Database=" + Database + | |
";Trusted_Connection=" + Trusted_Connection + ";"; | |
} | |
/// <summary> | |
/// Creates a connection string with Standard Security | |
/// </summary> | |
/// <param name="sqc">Sql Connection Object</param> | |
/// <param name="Data_Source">Database Name</param> | |
/// <param name="Init_Catalog">Table Name</param> | |
/// <param name="User_Id">User Name</param> | |
/// <param name="Password">Password</param> | |
public static void CS_SqlStandard(this SqlConnection sqc, string Data_Source, string Init_Catalog, string User_Id, string Password) | |
{ | |
sqc.ConnectionString = "Data Source=" + Data_Source + | |
";Initial Catalog=" + Init_Catalog + | |
";User Id=" + User_Id + | |
";Password=" + Password + ";"; | |
} | |
public static void CS_SqlStandard(this SqlConnection sqc, string Server, string Database, string User_ID, string Password, bool Trusted_Connection) | |
{ | |
sqc.ConnectionString = "Server=" + Server + | |
";Database=" + Database + | |
";User Id=" + User_ID + | |
";Password=" + Password + | |
";Trusted_Connection=" + Trusted_Connection + ";"; | |
} | |
public static void CS_OleStandard(this OleDbConnection ocs, string Your_Server_Name, string Your_Database_Name, string Your_Username, string Your_Password) | |
{ | |
ocs.ConnectionString = "Provider=SQLOLEDB;Data Source=" + Your_Server_Name + | |
";Initial Catalog=" + Your_Database_Name + | |
";UserId=" + Your_Username + | |
";Password=" + Your_Password + ";"; | |
} | |
public static void CS_OleTrusted(this OleDbConnection ocs, string Your_Server_Name, string Your_Database_Name) | |
{ | |
ocs.ConnectionString = "Provider=SQLOLEDB;Data Source=" + Your_Server_Name + | |
";Initial Catalog=" + Your_Database_Name + ";Integrated Security=SSPI;"; | |
} | |
} | |
} |