简体   繁体   English

如何从存储在表中的连接字符串连接到 SQL Server 数据库?

[英]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.

相关问题 什么是通过SQL Server连接到master数据库的连接字符串 - What is the connection string to connect to the master database via SQL Server 如何查看用于连接到SQL Server的连接字符串 - How to see the connection string used to connect to SQL Server 如何从表(SQL Server数据库)中将值选择为参数(存储过程)? - How to select values from a table (SQL Server database) into a parameter (Stored Procedure)? 如何使用存储过程将datetime插入SQL Server数据库表中? - How to insert datetime into a SQL Server database table with a stored procedure? 没有连接字符串即可连接到数据库服务器 - connect to database server without connection string 什么是 sql server 连接字符串中的“连接超时”? - What is “Connect Timeout” in sql server connection string? 如何从另一台 PC 和另一个连接连接到我的 sql 数据库? - how to connect from another PC and another connection to my sql database? 如何定义SQL Server 2008数据库的连接字符串? - How to define a connection string to a SQL Server 2008 database? SQL Server存储过程从另一个数据库表更新一个数据库表 - SQL Server stored procedure to Update one database table from another database table 每当我连接到SQL Server数据库时,是否都必须使用附加连接字符串? - Do I have to use attach connection string whenever I connect to a SQL Server database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM