I’m making complete connection strings inside my procedure and would like to inject the name of the database server in them. Is there any way that I can detect the name from inside or am I doomed to passing it in?
I’m making complete connection strings inside my procedure and would like to inject the
Share
Use SERVERPROPERTY:
SERVERPROPERTY('MachineName'): name of the SQL Server host name, cluster awareSERVERPROPERTY('ComputerNamePhysicalNetBIOS'): name of physical machine name. In a cluster, is the name of the current active node. On a standalone instalation, is identical with MachineNameSERVERPROPERTY('InstanceName'): name of the current SQL Server instance. NULL for default.One thing I’d recomend against is the dreaded @@SERVERNAME. This property is notorious for getting out of sync with reality after a machine rename. I’ve seen way too many apps burned by this problem to place any trust on it. The correct rename procedure is in BOL, but few use it properly: How to: Rename a Computer that Hosts a Stand-Alone Instance of SQL Server.