[英]How to connect to a SQL Server database from a connection string stored in a table ?
I have a table called 'A' with these fields '{ id, Connection String}'我有一个名为 'A' 的表,其中包含这些字段 '{ id, Connection String}'
and In Sql Server, I want to excecute a command that connect to the first database in 'A' table from it's connection string and query it's table data.在 Sql Server 中,我想执行一个命令,从它的连接字符串连接到“A”表中的第一个数据库并查询它的表数据。
Sudo code: select * from [db_connectionstring].dbo.mytable
须藤代码:
select * from [db_connectionstring].dbo.mytable
Is this achievable ?这是可以实现的吗? I hop some one can help me here.
我希望有人可以帮助我。 :)
:)
You can use the information in your table to generate and execute a您可以使用表中的信息来生成和执行
EXEC master.dbo.sp_addlinkedserver
https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addlinkedserver-transact-sql https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addlinkedserver-transact-sql
Statement then use the linked server you have created, you would have to check if you have already created the linked server.语句然后使用您创建的链接服务器,您必须检查您是否已经创建了链接服务器。
this is better done from your app and not SQL server.这最好从您的应用程序而不是 SQL 服务器完成。
No, SQL Server can't connect to other SQL Servers via a connection string.不可以,SQL Server 无法通过连接字符串连接到其他 SQL Server。 It can do it via Linked Servers, provided they are set up in advance.
它可以通过链接服务器来完成,前提是它们提前设置。
Maybe it could be done in a CLR procedure.也许它可以在 CLR 过程中完成。 Otherwise, what you are trying to do needs to be done in an external app.
否则,您尝试做的事情需要在外部应用程序中完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.