Skip to content
Advertisement

SQL Server – OPENROWSET Server name error using parameters

I’m having trouble with this query…Any idea how to declare variables and make it visible to OPENROWSET query?

Error:

Named Pipes Provider: Could not open a connection to SQL Server [53].

Advertisement

Answer

You can’t use a variable within a literal string. In your connection you’re stating you want to connect to a server actually called "@SERVERNM", not the value of @SERVERNM. Also, as you have DECLARE @SERVERNM VARCHAR, which is the same as DECLARE @SERVERNM VARCHAR(1). I suspect this might work but assumes @SERVERNM will have a value of less than or equal to 128 characters:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement