To create a database file in your visual project, go to the "add new item" and add a service based database file, then in your solution explorer, double click on the .mdf file. The database instance opens in server explorer automatically. right click on the database instance and click on "modify connections" (before you do this make sure you close the connections first). Click on "Change..." and in the new tab select "Microsoft SQL Server". when the former tab reopens type "(LocalDB)\v11.0" as your server name. click on the radio button "attach a database file". Select browse, and browse to the database.mdf file which you created (It is located in your project folder by default). After selecting the file, give the project a logical name of your choice (do not use punctuations because this might affect its backup if you want to put a backup code). click ok.
To get the connection string for your database instance, go back to "modify connections", click on "advanced", copy the connection string which will appear at the bottom of the new window.
No comments:
Post a Comment