How To Connect Database In Asp.Net

Published on Feb. 18, 2013

Follow this step by step guide to connect a sql server database in Don't forget to check out our site for more free how-to videos! - our feed - join us on facebook - our group in Google+ In this tutorial we will learn about connecting database, using is contained on a .net framework, which is supported by many IDE's. Usually, Visual Studio is used and heard. Database connection needs to be maintained, in order to communicate and manipulate data effectively. It is fetched, inserted, and displayed on your display using the choice of language, or syntax allotted to it. Step # 1 -- Opening your IDE and Selecting ASP.Net First of all we'll need to open our IDE, In my case Visual Studio. Make sure you select the ASP.Net website template in the Visual C#. Step # 2 -- Configuring Data Source Connecting database is easy, first add a button from the toolbar and name it. Then drag and drop the sqldatasource option from the toolbox. Click on configure data source in order to get your connection string. Step # 3 -- Generating connection string Here we create a new connection by clicking on the button with the same name. Then we put the server name and select a database, I am going to use tempdb as my database. Now click on test connection in order to see if the database connection is established. Step # 4 --Copy connection string Copy the connection string from this window because we'll need it while configuring the button event handler in the code. Step # 5 --Connecting the database In the code, first of all add the sql client system class library. Then paste the connection string behind the event handler of our My connection button and finally in order to establish the connection we use the Open method.