Error: 'Must declare the scalar variable @user_name'

  • ID dell'articolo: 117445
  • Aggiornato il: 18 mag 2012

Issue

When attempting to run the SQL script provided in our Sophos Upgrade Advisor documentation the script fails to run and you see an error similar to the following:

C:\>sqlcmd -E -S .\sophos -i db.sql
Msg 137, Level 15, State 1, Server SERVER-NAME\SOPHOS, Line 2
Must declare the scalar variable "@user_name".
Msg 137, Level 15, State 2, Server SERVER-NAME\SOPHOS, Line 16
Must declare the scalar variable "@user_name".

First seen in

Enterprise Console 5.1.0

Operating systems
Windows 2000 only.

Cause

This error is only seen when upgrading a Windows 2000 Server computer installed with Enterprise Console 4.0.

The script provided is incomplete and requires an additional line to function correctly.

What To Do

  1. Open the previously created script with a text editor and add the addition line:
    DECLARE @user_name NVARCHAR(128);
  2. Save the file and re-run the command.

Technical Information

The full script should be:

DECLARE @user_name NVARCHAR(128);
SET @user_name = (SELECT TOP(1)
[name]
FROM
sys.database_principals
WHERE
[name] LIKE '%Sophos DB Admins');
DECLARE @login_name NVARCHAR(128);
SET @login_name = (SELECT TOP(1)
[name]
FROM
sys.server_principals
WHERE
[name] LIKE '%Sophos DB Admins');
DECLARE @sql NVARCHAR(max);
SET @sql = N'ALTER USER [' + @user_name + N'] WITH LOGIN = [' + @login_name + N']';
EXEC sp_executesql @stmt = @sql;

 
Per maggiori informazioni o per assistenza, vi preghiamo di contattare il supporto tecnico.

Valutate l'articolo

Molto scadente Eccellente

Commenti