Search code examples
sqlsql-serverdatabasedatabase-connectionsql-server-2014

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}'

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.

Sudo code: select * from [db_connectionstring].dbo.mytable

Is this achievable ? I hop some one can help me here. :)


Solution

  • No, SQL Server can't connect to other SQL Servers via a connection string. It can do it via Linked Servers, provided they are set up in advance.

    Maybe it could be done in a CLR procedure. Otherwise, what you are trying to do needs to be done in an external app.