简体   繁体   English

如何连接到数据库项目?

[英]How to connect to a database project?

I have a team working on a project. 我有一个团队在做一个项目。 For the purpose of collaboration we are using Team Foundation Server . 为了进行协作,我们使用Team Foundation Server

Now we want to create a shared database so that each team member can connect to the database, manipulate it, and retrieve data. 现在,我们要创建一个共享数据库,以便每个团队成员都可以连接到该数据库,对其进行操作并检索数据。

I've already created a SQL Database Project and I've added it to TFS but I don't know how to connect to it from my code ? 我已经创建了一个SQL Database Project ,并将其添加到TFS中,但是我不知道如何通过我的代码连接到它?

The SQL Database Project is just a representation of the database schema and objects. SQL数据库项目只是数据库架构和对象的表示。 It isn't a database that you "connect to". 它不是您“连接”到的数据库。

Instead you will need a SQL server running somewhere. 相反,您将需要在某个地方运行的SQL Server。 You might decide to run it locally on each of your dev machines or have a common server that everyone accesses. 您可能决定在每台开发机上本地运行它,或者拥有一个供所有人访问的公用服务器。 Either way, a regular SQL server needs to be installed somewhere. 无论哪种方式,都需要在某个地方安装常规的SQL Server。

This doesn't have anything to do with TFS. 这与TFS无关。 This is just a Visual Studio project like any other. 与其他任何项目一样,这只是一个Visual Studio项目。

What exactly do you mean by "connect to it from my code"? “从我的代码连接到它”到底是什么意思? .NET code doesn't directly interact with a database project , but can form a data access layer to interact with a database . .NET代码不会直接与数据库项目交互,但是可以形成数据访问层与数据库交互。

If you right-click on the database project in Visual Studio, there is an option to deploy (or perhaps publish, depending on the Visual Studio version). 如果在Visual Studio中的数据库项目上单击鼠标右键,则可以选择部署(或发布,具体取决于Visual Studio版本)。 You can deploy the database project to a live database and then your .NET code can interact with that database. 您可以将数据库项目部署到活动数据库中,然后.NET代码可以与该数据库进行交互。

This can be multiple databases. 这可以是多个数据库。 For example, your automated builds can deploy to a shared database for everyone to use, and individual developers can deploy to their local workstations for development and debugging purposes. 例如,您的自动构建可以部署到共享数据库供所有人使用,并且各个开发人员可以部署到其本地工作站进行开发和调试。

The Sql Database project is not a database in itself - it is a project that describes a database. Sql Database项目本身不是数据库,而是描述数据库的项目。 You need to deploy that project (typically to an instance of Sql Server) in order to connect to it in the way you describe. 您需要部署该项目(通常部署到Sql Server实例),以便以您描述的方式连接到该项目。

In a typical team development environment, each member of your team might have their own local instance of Sql Server, and deploy the project to it. 在典型的团队开发环境中,团队的每个成员都可能拥有自己的Sql Server本地实例,并将项目部署到该实例。 In this way, your team members won't get in eachother's way as they create and delete data during the course of development. 这样,您的团队成员在开发过程中创建和删除数据时就不会互相妨碍。 You will possibly also want a shared instance for a more formal testing environment. 您可能还希望共享实例用于更正式的测试环境。

So ultimately, what you've created is not a shared database: it's a template that a database can be created from. 因此,最终,您创建的不是共享数据库:这是可以从中创建数据库的模板。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM