SqlConnection Class ADO.NET | SqlConnection C# | SqlClient SqlConnection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace SQLConnectionADO
{
internal class Program
{
static void Main(string[] args)
{
Program.Connection();
Console.ReadLine();
}
static void Connection()
{
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
SqlConnection con = null;
try
{
using (con = new SqlConnection(cs))
{
con.Open();
if (con.State == ConnectionState.Open)
{
Console.WriteLine("Connection has been Created Successfully !!");
}
}
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
con.Close();
}
}
//static void Connection()
//{
// string cs = "Data Source=HEER\\SQLEXPRESS;Initial Catalog=ado_d;Integrated Security=true;";
// SqlConnection con = null;
// try
// {
// using (con = new SqlConnection(cs))
// {
// con.Open();
// if (con.State == ConnectionState.Open)
// {
// Console.WriteLine("Connection has been Created Successfully !!");
// }
// }
// }
// catch (SqlException ex)
// {
// Console.WriteLine(ex.Message);
// }
// finally
// {
// con.Close();
// }
// //using(SqlConnection con = new SqlConnection(cs))
// //{
// // con.Open();
// // if (con.State == ConnectionState.Open)
// // {
// // Console.WriteLine("Connection has been created successfully.");
// // }
// //}
// //SqlConnection con = new SqlConnection(cs);
// //try
// //{
// // con.Open();
// // if (con.State == ConnectionState.Open)
// // {
// // Console.WriteLine("Connection has been created successfully.");
// // }
// //}
// //catch (SqlException ex)
// //{
// // Console.WriteLine(ex.Message);
// //}
// //finally
// //{
// // con.Close();
// //}
//}
}
}
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments
Post a Comment