简体   繁体   English

如何在SQL Server Management Studio中使用Visual Studio创建连接数据库?

[英]How connect database created in SQL Server Management Studio with Visual Studio?

I've created a database Test1 in Microsoft SQL Server Management Studio and I would like to connect this database to my VS C# project. 我在Microsoft SQL Server Management Studio中创建了一个数据库Test1 ,我想将此数据库连接到我的VS C#项目。 I found this question where are instructions how to connect just system databases (tables master, model, msdb and tempdb). 我发现这个问题在哪里说明如何只连接系统数据库(表master,model,msdb和tempdb)。 Is there some way how to connect user-created table to my VS project? 有没有办法将用户创建的表连接到我的VS项目?

Thank you for your answers and I hope that my problem is understandable. 感谢您的回答,我希望我的问题是可以理解的。

在此输入图像描述

Probably not the best way, but from Visual Studio: 可能不是最好的方法,但是来自Visual Studio:

  • Open the Server Explorer panel 打开Server Explorer面板
  • Click "Connect to Database" 单击“连接到数据库”

From here, there are two options depending on whether the database above was created for SQL Server or as a SQL Express file. 从这里开始,有两个选项,具体取决于上面的数据库是为SQL Server创建还是作为SQL Express文件创建的。

  • If the database came from a SQL Express .mdf file, select "Microsoft SQL Server Database File (SqlClient)" as the data source, and browse for the .mdf file. 如果数据库来自SQL Express .mdf文件,请选择“Microsoft SQL Server数据库文件(SqlClient)”作为数据源,然后浏览.mdf文件。

OR 要么

  • If the database resides in SQL Server, change the data source to "Microsoft SQL Server" 如果数据库驻留在SQL Server中,请将数据源更改为“Microsoft SQL Server”
  • Enter localhost as the server name. 输入localhost作为服务器名称。 This should enable the dropdown list under "Select or enter a database name." 这应该启用“选择或输入数据库名称”下的下拉列表。
  • Select Test1 from the drop down. 从下拉列表中选择Test1。

You should now see Test1 under data connections in the Server Explorer pane, finally: 您现在应该在Server Explorer窗格中的数据连接下看到Test1,最后:

  • Right click on it and select properties. 右键单击它并选择属性。
  • In the properties pane, you will see the Connection String which you can use to connect to the database with code in your project. 在属性窗格中,您将看到可用于使用项目中的代码连接到数据库的连接字符串。 From here, it depends on what type of project you have. 从这里开始,这取决于您拥有的项目类型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio或SQL Server Management Studio中连接到Azure SQL数据库的哪些必要步骤? - Which are necessary steps to connect to an Azure SQL database in Visual Studio or SQL Server Management Studio? 如何将在 Visual Studio C# 中创建的数据库迁移到 SQL 服务器? - How to migrate a DataBase created in Visual Studio C# to a SQL Server? SQL Server Management Studio无法连接 - SQL Server Management Studio can not connect 无法将Visual Studio连接到SQL Server数据库 - Can't connect Visual Studio to SQL Server database 使用C#连接到SQL Server 2012数据库(Visual Studio 2012) - Connect to SQL Server 2012 Database with C# (Visual Studio 2012) 通过SQL Server Management Studio 2008连接数据库,但不通过Visual Studio 2012连接数据库 - connecting database through sql server management studio 2008 but not through visual studio 2012 在SQL Server Management Studio中找不到数据库 - Unable to find database in SQL Server Management Studio Visual Studio 未从 Microsoft SQL Server Management Studio 加载数据 - Visual studio not loading data from Microsoft SQL Server Management Studio 如何使用Visual Studio 2015连接到ASP.NET中的本地SQL Server数据库? - How to connect to a local SQL Server database in ASP.NET using Visual Studio 2015? 如何使用Visual Studio 2013连接到asp.net中的本地SQL Server数据库? - How to connect to a local SQL server database in asp.net using Visual Studio 2013?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM