Monday 18 June 2018

Connect to localDB database using WinForms in C#

This is simple tutorial of how to connect with localDB DB, I've made this tutorial because I've seen a lot of people facing issues while connecting with databases. First part of this tutorial is about localDB connectivity using ADO.NET, you can also use any ORM for this purpose like EF, NHibernate etc. I'm doing this in a traditional way.
Lets jump into the code, first create any application i.e. windows form, wpf, asp.net (webform or mvc), I've used WinForm for this purpose. Verify whether localDB is installed or not by going into control panel, add remove programs.
Follow the given
steps for connectivitiy:
1) Create new application
2) goto Tools->Connect to database
3) Enter the instance name i.e. (localdb)\V11.0 and click on test connection or drop down with label "Select or enter database name"
4) If there comes an error like "A network related instance..."
go back to step 2 and enter the instance name (localdb)\MSSQLLocalDB again click on test connection or drop down of selecting database
5) It will successfully connect to the database
6) The connection with the database has been established, it will be showing in your Server Explorer
7) Right click on your database within Server Explorer
8) Goto->Properties, there will be a dialog box with information about the DB, you can get Connection string from there and use it within your application for the db connectivity, I've attached the images, Have a look.
Hope it helps the people who faces difficulty in this step with localDb. Next part will contain the connectivity with SqlServer Database.


Images are attached for better understanding:







No comments:

Post a Comment