[英]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 :解决方法:
Add the database name before the objects names:在对象名称之前添加数据库名称:
SELECT * FROM [database name].[schema name].[table name]
Execute queries inside batches:在批次内执行查询:
EXEC('Use mydatabase; SELECT * from [schema name].[table name]')
Additional information附加信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.