How do I create a database created in SQL Server Management Studio with Visual Studio?

I created a database Test1

in Microsoft SQL Server Management Studio and I would like to connect this database to my VS C # project. I found this question which has instructions for connecting only system databases (master tables, model, msdb and tempdb). Is there a way to link a user created table to my VS project?

Thanks for your answers and I hope my problem is clear.

enter image description here

+3


source to share


1 answer


This is probably not the best way, but from Visual Studio:

  • Open the Server Explorer panel
  • Click "Connect to Database"

There are two options here depending on whether the database was created for SQL Server or as a SQL Express file.

  • If the database comes from a SQL Express.mdf file, select Microsoft SQL Server Database File (SqlClient) as the data source and locate the .mdf file.


OR

  • If the database is in SQL Server, change the data source to "Microsoft SQL Server"
  • Enter localhost as the server name. This should include a dropdown under Select or Enter Database Name.
  • Select Test1 from the dropdown list.

You should now see Test1 under the data connections in the Server Explorer pane, finally:

  • Right click on it and select properties.
  • In the properties panel, you will see a connection string that you can use to connect to a database with code in your project. From here, it depends on what kind of project you have.
+5


source







All Articles