Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
I need a c# class that contains methods to open and close connection to SQl server. I want to use this methods in other classes of the project.
Posted
Comments
What have you tried and where is the problem?

There are so many Options Like You can use Sql Helper Class See this SQL Helper class.
or SQL Helper Class Microsoft .NET Utility
and also C# - SQL Helper Class
 
Share this answer
 
What you "need" is the ability to Google.

The .Net framework has comprised on ADO.Net[^] since version 1.1.
ADO.Net provides all the classes you need to connect with a variety of different database types including SQL. (Which uses the System.Data.SQLClient namespace).

I suggest you have a read on that and also on the FAQ on this forum for how to post questions as it will provide you with guidance on how you aught to approach posting questions here in order to get the best response.
 
Share this answer
 
The sql connection get easy way u didnot reconfigure your just hardcoded the

following for windows authentication

C#
string connection=datasource="servername" intial catalog="databasename" integrated security="true"


sql server authetication like


C#
string connectiondatasource="servername" intial catalog="databasename" Persistinfo security="true" userid="sa"password="123"



to reconfigure the connection string just use txt file or xml
i example to things
place the debug folder dbpathi.ini file (crete new txt file save with extension .ini file )


SQL
datasource="servername" intial catalog="databasename" integrated security="true" <pre lang="SQL">



enter following connection strings

to the simple code


C#
filestream fs=new file stream();
fs=file.open(appdomain.currentdomain.basedirectory+"Dbpath.ini");

streamreader sa=new stream reader(fs);
string reader=sa.readtoend()

sqlconnection connnctoin=new sqlconection(reader);
conection.open()
=
 
Share this answer
 
you need a SqlConnection class for connectivity Sql server like that
C#
static SqlConnection _con = new SqlConnection("Connection String");

and another need a Sqlcommand for pass a Query front to Back end Server.
C#
SqlCommand _cmd;
 _cmd = new SqlCommand("SELECT *  FROM Table_Name WHERE ColoumnName like '%" + name + "%'", _con);
            _con.Open();
            _rd = _cmd.ExecuteReader();
            dt1 = new DataTable();
 dt1.Load(_rd);
_con.Close();


For any query left the comment.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900