Monday 18 June 2018

Connect to SQL Server database in c#

This tutorial will help you on how you can connect to the SQL Server database using visual studio windowsForms. You can follow this tutorial for webforms or asp.net too( little modifications within web.config). Follow these steps to get connected with the SQL Server.
1) Create a database(If not exists) within sql server by connecting it with your account localhost or whatever your server name is.
2) Goto visual studio clicks on the tools->Connect to Databases
3) A dialog box will appear, in the server name just write '.'(dot) which states that you are going to connect with the databases within your local account.
4) Click on the select or enter database drop down, there will appear all the databases that your account holds.
5)
Select database, the one you wanted to connect to.
6) Click server explorer within your visual studio, A connection would be automatically created there, write click on the db, copy the connection string from there and use that connection string within your application.
I've attached all the images with step number.
If you don't understand anything within sql server/visual studio/c#/desktop/web, please make a post here, I'll try my best to help you.








No comments:

Post a Comment