Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How Set-up a dabase of sql server 2005 in Asp.net with c#??
Posted
Comments
Wild-Programmer 12-Apr-11 23:51pm    
Your question has generated ambiguous error.
Please try explaining it again ;)

Hope you are asking about how to set-up a connection to sql server 2005 through C# in Asp.net. If so Check the below code...


XML
<connectionStrings>
    <add name="OsmEmpConString" connectionString="Data Source=.\sqlexpress;Initial Catalog=AgentDB; User ID= Sqluser ; Password= Change123;"
    providerName="System.Data.SqlClient" />
  </connectionStrings>


Create the connection in web.config file and establish a connection
DataSource = Your database source
Initial Catalog = Database name
User ID = User id of the database
Password = Password to the database

Use that connection in your .cs file... You can check the below code

MIDL
string strDbCon = WebConfigurationManager.ConnectionStrings["OsmEmpConString"].ToString();
    SqlConnection _cnAgentDB = new SqlConnection(strDbCon);
       _cnAgentDB.Open();

_cnAgentDB is the instance of SqlConnection.

Before going to do this, u need to add two namespaces in the .cs file,
they are
C#
using System.Web.Configuration;
using System.Data.SqlClient;
 
Share this answer
 
v4
Comments
Sandeep Mewara 13-Apr-11 6:40am    
My 5! Good enough to start with..
sqlconnection con=new sqlconnection("connection string");
sqldataadaptor adp=new sqldataadaptor("Select query",con);
dataset ds=new dataset();
adp.fill(ds);

Now you have the values in dataset
 
Share this answer
 
Comments
Sandeep Mewara 13-Apr-11 6:40am    
Avoid posting it multiple times.

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