How to Pass Static Sqlconnection in 3Tier Arch using c#

Posted by Dotnet4ashu under ASP.NET on 3/10/2012 | Points: 10 | Views : 2654 | Status : [Member] | Replies : 5
Hello Experts,

Can anybody tell me how to create a static SqlConnection in a class of 3tier-Arch using C sharp. Which could be easy to call ( its object ) on DataAccessLayer (DAL).

Himanshu Sharma
If you see Dreams then Get Success On Dreams.....



Responses

Posted by: Raj_Chennai on: 3/12/2012 [Member] Starter | Points: 25

Up
0
Down
hi use this in separate class ,
public static SqlConnection con = new SqlConnection("Data Source=raj-pc;Initial Catalog=sampleDB;Integrated Security=True");
public static void Open()
{

con.Open();
}
public static void Close()
{
con.Close();
}

raj

Dotnet4ashu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnet4ashu on: 3/12/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks brother i am very thankful to you i apply it on 3tier as well as on 2tier Arch using only c#................

Himanshu Sharma
If you see Dreams then Get Success On Dreams.....

Dotnet4ashu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Denny on: 3/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
create a class for connection & write this code

using System.Data.SqlClient;
string strConnection="@server=your server name;initial catalog=your db name;integrated security=true";
public static SqlConnection sqlcon=new SqlConnection(strConnection);
public void ConState()
{
if(sqlcon.State==ConnectionState.Open) //if connection is Open it will close
{
sqlcon.Close();
}
if(sqlcon.State==ConnectionState.Closed)
{
sqlcon.Open();
}

}

Regards,
Denny Kurian

Dotnet4ashu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj_Chennai on: 3/15/2012 [Member] Starter | Points: 25

Up
0
Down
hi if it is answer mark it so it will be useful to everyone

raj

Dotnet4ashu, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi try this,
its realy helpful

http://www.dotnetfunda.com/blogs/hmanjarawala/1699/sql-helper-class


Mark this as answer, if it helps you..............

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Dotnet4ashu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response