Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 database connection

Author  Topic 

bazzano
Starting Member

11 Posts

Posted - 2010-01-27 : 01:10:09
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

22859 Posts

Posted - 2010-01-27 : 03:22:38
See www.connectionstrings.com for database connection strings.
Go to Top of Page

kirangentlebreeze1987
Starting Member

14 Posts

Posted - 2010-02-12 : 03:48:01
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
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2010-02-12 : 14:21:17
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
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2010-02-12 : 14:23:01
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

14 Posts

Posted - 2010-02-12 : 16:29:25
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
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2010-02-12 : 18:10:31
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

2 Posts

Posted - 2010-02-17 : 07:57:36
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 - 2010-03-02 : 04:45:51
You can try the code below:

SqlConnection con=new SqlConnection("server=;database=;uid=;pwd=");
con.Open();
Go to Top of Page

jet1337
Starting Member

11 Posts

Posted - 2010-03-16 : 03:14:09
thanks man that works great

ASPnix.com
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2010-03-18 : 10:17:33
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
   

- Advertisement -