how to connect sql server in c#

Posted by Jayapal.c under C# on 11/23/2011 | Points: 10 | Views : 20062 | Status : [Member] | Replies : 6
im a beginner in c# .i try to connect database in c# but not connect.please tell me the how to connect the ms sql2005 in c#




Responses

Posted by: muralikrishnasurap-12704 on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi ,
We have using.system.Data.SqlCilent name space available in C#,it contains list of class that are used for connecting SQL Server
SqlConnection class where we can pass connection string in constructor connection string contains
Userd="userid of sql server"
Password="Password of id account"
Server="server details"
database="databasename"
connectiontimeout="30"

once SQlConnection object is created use Open() method to access the data base.


Best Regards
Murali Krishna.S

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

Posted by: Biswarup90 on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Standard Security:
------------------
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

myServerAddress :-
Server Name in your SSMS
myDataBase :
"Database name" you want to connect with your database.
myUsername :
UserName in your SSMS
myPassword
Your Password in SSMS

-----
Standard Security Alternative Syntax:
-------------------------------------
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;


Connect via an IP address:
--------------------------
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;


---------

Server=Biswarup\\SQLEXPRESS;Database=CMS;Integrated Security=SSPI
It is my server name.



Biswarup Ghosh

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

Posted by: Rajeev.Shukla on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
If you are using Asp.Net application, use this link

http://msdn.microsoft.com/en-us/library/ff648340.aspx

If you are using Windows or Console application use this link.

http://www.codeproject.com/KB/database/sql_in_csharp.aspx

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

Posted by: perfectchourasia-9163 on: 11/29/2011 [Member] Starter | Points: 25

Up
0
Down
<add key="linkbuilding" value="server=.;database=Database name; uid=User ID;pwd=Password;"/>


Use this connection string in the code page :-
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["linkbuilding"].ToString().Trim());

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Posted by: balajirnaukri-12656 on: 12/1/2011 [Member] Starter | Points: 25

Up
0
Down
"Server="Your Server name"\\SQLEXPRESS;Database="Databasename";Integrated Security=true"

Thanks and Regards
Balaji.R
ASP.NET Devloper
Solve-IT corp

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

Posted by: Varung on: 12/3/2011 [Member] Starter | Points: 25

Up
0
Down
in your web.config file
add this code
<connectionStrings>
<add name="connection" connectionstring="server=.;database=Database name; uid=User ID;pwd=Passwor"/>
</connectionStrings>

and in your .cs file use below code

SqlConnection con=new SqlConnection(ConfigurationManager.Connectionstring["connection"].connectionstrings);



G.Varun

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

Login to post response