简体   繁体   English

如何在 Visual Studio 中设置 SQL 数据库项目中的数据库连接字符串?

[英]How to have database connection string in the SQL Database Project set up in the Visual Studio?

How to have database connection string in the SQL database project set up in the Visual Studio?如何在 Visual Studio 中设置 SQL 数据库项目中的数据库连接字符串?

Database project has stored procedures, functions etc.数据库项目有存储过程、函数等。

When we keep the syntax当我们保持语法

use mydatabase
go

inside the stored procedure, build is throwing error.在存储过程中,build 抛出错误。

When I remove the statement use mydatabase , there is no build error.当我删除语句use mydatabase ,没有构建错误。

At present, we don't have a connection string or config file for the SQL database project.目前,我们没有 SQL 数据库项目的连接字符串或配置文件。 My clarification is, whether having the connection string will allow the use syntax?我的澄清是,是否拥有连接字符串将允许使用语法?

Note: I am using Visual Studio 2017注意:我使用的是 Visual Studio 2017

You cannot add a USE statement inside a stored procedure or function, even in SQL Server Management Studio.您不能在存储过程或函数中添加USE语句,即使在 SQL Server Management Studio 中也是如此。

If mydatabase is the current database project then you don't need it since it is meaningless.如果mydatabase是当前的数据库项目,那么您不需要它,因为它毫无意义。

Workarounds :解决方法

  1. Add the database name before the objects names:在对象名称之前添加数据库名称:

     SELECT * FROM [database name].[schema name].[table name]
  2. Execute queries inside batches:在批次内执行查询:

     EXEC('Use mydatabase; SELECT * from [schema name].[table name]')

Additional information附加信息

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

相关问题 在Visual Studio Express 2013中为C#项目的本地测试设置SQL数据库的最简单方法 - Easiest way to set up SQL Database for local testing of C# project in Visual Studio Express 2013 如何将断开视图添加到Visual Studio SQL Server数据库项目 - How to add breaking views to an Visual Studio SQL Server Database Project Visual Studio中的数据库连接 - Database connection in Visual Studio Visual Studio 2017 SQL数据库项目 - Visual Studio 2017 SQL database project Visual Studio数据库项目和SQL Server管理 - Visual Studio Database Project and SQL Server Management 从 Visual Studio 2013 数据库项目中清理 SQL Server 数据库 - Clean SQL Server database from Visual Studio 2013 database project 如何在Visual Studio 2013中创建数据库项目 - How to create a database project in Visual Studio 2013 在 Visual Studio 中使用 VB.NET 连接到本地 SQL 数据库的连接字符串问题 - Connection string problem connecting to local SQL database using VB.NET in Visual Studio 无法使用 Visual Studio 通过 VB.NET 中的连接字符串手动访问本地 SQL 数据库 - Can't access Local SQL database manually by connection string in VB.NET using Visual Studio 如何使用 Visual Studio 更新 SQL 数据库? - How to update an SQL database using visual studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM