简体   繁体   English

以另一用户身份连接到同一数据库,而无需对连接字符串进行硬编码

[英]Connect to the same database, but as a another user, without hardcoding a connection string

Can I use OPENDATASOURCE (or another mechanism) from a Stored Procedure to connect to the same database as a different user? 是否可以使用存储过程中的OPENDATASOURCE (或其他机制)以其他用户身份连接到同一数据库? If so, how? 如果是这样,怎么办?

The database is meant to be deployed to several customers, and replicated by them as many times as they want to, etc. For this reason, I CANNOT HARDCODE the database server's name or the database's name. 该数据库打算部署到多个客户,并由他们进行多次复制, 以此类推 。因此,我无法对数据库服务器的名称或数据库名称进行硬编码

(I tried using OPENDATASOURCE , but it only accepts hardcoded connection strings.) (我尝试使用OPENDATASOURCE ,但它仅接受硬编码的连接字符串。)

Might EXECUTE AS work in your situation? 可以在您所处的环境中EXECUTE AS吗? http://msdn.microsoft.com/en-us/library/ms181362.aspx http://msdn.microsoft.com/en-us/library/ms181362.aspx

You can set up a Linked Server to connect to the remote server using the login's current security context (or other options as it applies to your situation). 您可以设置链接服务器以使用登录名的当前安全上下文(或其他适用于您情况的选项)连接到远程服务器。

From your stored procedure, you could access it with something like SELECT * FROM mylinkedservername.mylinkedserverdatabase.dbo.mytable 从存储过程中,您可以使用SELECT * FROM mylinkedservername.mylinkedserverdatabase.dbo.mytable类的方式访问它

But you say you want to connect to the same database but using a different login? 但是您说要连接到相同的数据库但使用不同的登录名吗? You're looking for impersonation. 您正在寻找模仿。 Perhaps you can do this making a Linked Server that references itself, I haven't tried it. 也许您可以这样做,使链接服务器引用自己,但我还没有尝试过。 Search Microsoft Help documentation for how to set it up normally and test if it does what you're looking to do. 在Microsoft帮助文档中搜索如何正常设置它,并测试它是否符合您的期望。

暂无
暂无

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

相关问题 配置SSIS包以从数据库中获取连接字符串,而不是在连接管理器中进行硬编码 - Configuring SSIS Package to fetch connection string from the database instead of hardcoding in the connection manager 从 T-SQL 存储过程中引用另一个数据库而不对数据库名称进行硬编码 - Referencing another database from T-SQL stored proc without hardcoding the database name 为什么我不能通过连接字符串连接到数据库? - Why I cant connect to the database by connection string? 如何访问连接字符串并连接到数据库 - How to access connection string & connect to database 如何在不使用where子句硬编码的情况下在同一表中找到相同的值? - How to find same value in same table without hardcoding in where clause? 没有用户 ID 或密码的连接字符串 - Connection string without User Id or Password 有没有办法查询SQL Server链接服务器而无需硬编码数据库名称? - Is there a way to query SQL Server linked server without hardcoding database name? 尝试不使用受信任的连接而连接到MDF数据库 - Trying to connect to MDF Database without using a trusted connection 可以使用相同的连接字符串连接到DAO中的数据源,但不能连接到ADO中的数据源 - Can connect to data source in DAO but not in ADO using the same connection string 连接字符串,用于使用其他Windows帐户连接SQL Server - Connection String to connect a SQL Server using another windows account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM