How to make database connectivity in asp.net?

Solved/Closed
Digvijaysinh
Posts
10
Registration date
Tuesday January 27, 2009
Status
Member
Last seen
July 6, 2009
- Updated on Jan 31, 2019 at 03:02 PM
 ARVIND - Apr 2, 2018 at 05:23 AM
Hello,

I am looking for the database connectivity in asp.net with sql server 2005 or NS Access 2007.

Can anyone help me?

Thanks in advance!
System Configuration: Windows XP Microsoft visual studio 2008,C#.

16 replies

Hi,

Please add the following code in your
aspx.cs
page:

Step 1: Add Namspace using System.Data.SqlClient;

Step 2: Make Sql connection.

Write this code to create Sql connection:
SqlConnection con = new SqlConnection("Server=You server name or comp name;Database=Yourdatabasename;Trusted_Connectopn=True");
SqlCommand cmd = new SqlCommand("Write your sql query here eg. select * from Table name");
con.Open();
DataSet ds = new DataSet(cmd,con);
SqlDataAdapter da = new SqlDataAdapter();
da.Fill(ds);
con.Close();


I hope this should work.

Thanks!
376
Hello

in a aspx.cs file I write connection string like
System.Data.SqlClient;
SqlConnection conn = new SqlConnection("Data Source=SYS014\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

but it is showing error at SYS014\ELLE message is unrecorgnized escape sequence. how to rectify that and how can I connect to database
0
sachith > av_deepu
Jun 17, 2009 at 02:33 AM
Hi,

I think your problem is with the "/" character.

SqlConnection conn = new SqlConnection("Data Source=SYS014\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

In the above line you use either @ sign in front like this

SqlConnection conn = new SqlConnection(@"Data Source=SYS014\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

or

use the '/' sign twice like this.

SqlConnection conn = new SqlConnection("Data Source=SYS014\\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");

Hope this will solve your problem
0
onks > av_deepu
Mar 4, 2010 at 10:19 AM
use this

SqlConnection conn = new SqlConnection("Data Source=SYS014\\ELLE;Initial Catalog=bank;User ID=sa;password=root;Integrated Security=True");
0
Following are the few of the benefits of MVC design pattern. > av_deepu
Mar 16, 2010 at 09:02 AM
Following are the few of the benefits of MVC design pattern.
0
avanish shakya
Apr 6, 2010 at 02:26 AM
thanks for connection string
0