SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 ASP.NET
 database connection
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bazzano
Starting Member

Australia
11 Posts

Posted - 01/27/2010 :  01:10:09  Show Profile  Reply with Quote
how i can set up a simple connection to my sql database

myserver name is mysqlserver
my table name is dbo.Products

Do i have to set up a connection string first in IIS?

How do i then set it up in ASP.net just to show some simple data first to test that it works?

Kristen
Test

United Kingdom
22403 Posts

Posted - 01/27/2010 :  03:22:38  Show Profile  Reply with Quote
See www.connectionstrings.com for database connection strings.
Go to Top of Page

kirangentlebreeze1987
Starting Member

India
14 Posts

Posted - 02/12/2010 :  03:48:01  Show Profile  Reply with Quote
open a text file,save it with extension .udl..after saving it click on that file...choose your provider...choose your intial catalog...open that udl file using notepad...you can see the connection string.... then

sqlconnection con=new sqlconnection("your connection string");
con.open();

if your provider is sqlserver

kkk
Go to Top of Page

afrika
Flowing Fount of Yak Knowledge

Nigeria
2706 Posts

Posted - 02/12/2010 :  14:21:17  Show Profile  Reply with Quote
quote:
Originally posted by bazzano


Do i have to set up a connection string first in IIS?




No, that would be totally wrong. IIS is the name of the web server software that hosts your website, e.g www.sqlteam.com is a website runing on IIS, and within your website you need to setup your website configurations e.g.

web.config file, will contain things like the membership provider and connection strings. For a detailed overview and how to learn see www.asp.net/learn
Go to Top of Page

afrika
Flowing Fount of Yak Knowledge

Nigeria
2706 Posts

Posted - 02/12/2010 :  14:23:01  Show Profile  Reply with Quote
Here is a sample connection string extract from my web.config file

<connectionStrings>

<add name="welcometoonenewday" connectionString="Data Source=127.0.0.1,4533;Network Library=DBMSSOCN;Initial Catalog=mydatabase;User ID='username';Password='password';" providerName="System.Data.SqlClient" />
</connectionStrings>

then in my code behind or classes, i then use the variable welcometoonenewday to reference the connection string, and 2nd use the ADO.NET properties to extract and create recordsets, database values etc
Go to Top of Page

kirangentlebreeze1987
Starting Member

India
14 Posts

Posted - 02/12/2010 :  16:29:25  Show Profile  Reply with Quote
yes man,you are correct...but i have put a simple way to establish a connection to his database...he is unaware of connection strings it seems...thats why i started elobarating how to make a simple connection to database

kkk
Go to Top of Page

afrika
Flowing Fount of Yak Knowledge

Nigeria
2706 Posts

Posted - 02/12/2010 :  18:10:31  Show Profile  Reply with Quote
quote:
Originally posted by kirangentlebreeze1987

yes man,you are correct...but i have put a simple way to establish a connection to his database...he is unaware of connection strings it seems...thats why i started elobarating how to make a simple connection to database

kkk



cool.

But its best to centralize your connection string in the web.config file and set it into a global variable open to all calling applications
Go to Top of Page

manassahu.it
Starting Member

India
2 Posts

Posted - 02/17/2010 :  07:57:36  Show Profile  Reply with Quote
I suppose you are using sql server database.

Best way is put your connection string in web.config. Because it is secure and you can acces this anywhere in your code.

<connectionStrings>
<add name="ConnStr" connectionString="Data Source=YourDatabaseName;User id=DatabaseUserID;Password=Databasepassword;Initial Catalog=DatabaseName;Connection TimeOut=100;Pooling=false" providerName="System.Data.SqlClient"/>
</connectionStrings>



My Blog : http://expertdevelopersblog.blogspot.com/
Manas Ranjan Sahu
Go to Top of Page

april198474
Starting Member

11 Posts

Posted - 03/02/2010 :  04:45:51  Show Profile  Reply with Quote
You can try the code below:

SqlConnection con=new SqlConnection("server=;database=;uid=;pwd=");
con.Open();

Edited by - april198474 on 06/05/2014 04:34:42
Go to Top of Page

jet1337
Starting Member

11 Posts

Posted - 03/16/2010 :  03:14:09  Show Profile  Visit jet1337's Homepage  Reply with Quote
thanks man that works great

ASPnix.com
Go to Top of Page

afrika
Flowing Fount of Yak Knowledge

Nigeria
2706 Posts

Posted - 03/18/2010 :  10:17:33  Show Profile  Reply with Quote
quote:
Originally posted by april198474

You can try the code below:

SqlConnection con=new SqlConnection("server=;database=;uid=;pwd=");
con.Open();


________________
April
My Free Live Chat Software for you.



its not a good practice to create ur connection string at runtime
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000