last day (17 days later) » 

14:21
3
Q: The specified @server_name ('') does not exist

halid.sertWe have an SQL Server 2019 instance (let's call it 'sample_instance') with server collation of 'Turkish_CI_AS'. When I try to create a job, SSMS creates the part of the script that adds the target server as following: EXEC msdb.dbo.sp_add_jobserver @job_name=N'_test_job', @server_name = N'SAMPLE_...

Dai
Dai
Have you tried using SERVERNAME so you don't need to have the text as a T-SQL string literal? e.g. DECLARE @self sysname = @@SERVERNAME; /* etc */ EXEC sp_dropserver @self; ?
Hi there. Something seems a little off here. Are you saying that you can't execute the job creation script on the same instance that the script was generated from? Which "i" character is in your @@SERVERNAME? Please execute SELECT @@SERVERNAME, CONVERT(VARBINARY(128), @@SERVERNAME); to verify (and update the question with the query result if you are allowed to). Is the name all upper or lower-case, or mixed? Also, please update the question with the output of this query: SELECT DATABASEPROPERTYEX(N'msdb', 'collation') AS [DB], SERVERPROPERTY('collation') AS [Instance];.
@Dai I tried that and the output is something like: The server 'sample_instance' does not exist. (for sp_dropserver) The server 'SAMPLE_INSTANCE' already exists. (for sp_addserver)
@SolomonRutzky select @@servername, serverproperty('servername') both print lowecase. However, when creating a job with SSMS, the script is created as uppercase for @server_name (Hence the incompatibility). As for the collation of MSDB and the instance, they are the same (Turkish_CI_AS). I don't think they can be different anyways.
Dai
Dai
@halid.sert When you say "creating a job" - do you mean you're using MSSQL Agent?
@halid.sert Thanks for that info. Yes, instance-level collation and system DB collation can be different, typically the result of restoring a system DB created on an instance using a different collation. Does the output of this query show the same values as the first query in my comment above: SELECT [name], CONVERT(VARBINARY(128), [name]) FROM sys.servers WHERE [server_id] = 0;. Also, what is the output of: SELECT DATABASEPROPERTYEX(N'master', 'collation');? Is it also "Turkish_CI_AS"?
14:21
@SolomonRutzky SELECT [name], CONVERT(VARBINARY(128), [name]) FROM sys.servers WHERE [server_id] = 0; returns uppercase while select @@servername, serverproperty('servername') both return lowecase. And all the system dbs' and instance's collation are Turkish_CI_AS.
@Dai Yes I'm using SQL Server Agent.
@halid.sert Thanks again for the info. When was the last time you restarted the instance? Can you restart the instance again and re-execute the two server name-based queries in your comment directly above this one. Is the output of @@servername, serverproperty('servername') different after the restart?
@SolomonRutzky I restarted it today but I can't remember at what point. I just restarted it and the results for SELECT [name], @@servername, serverproperty('servername')FROM sys.servers WHERE [server_id] = 0; is uppercase, uppercase and lowercase now. However, the same error persists. I'm currently at the 9th hour of my workday and I might not be able to see something obvious if there is any :)
@halid.sert Just to confirm: both [name] FROM sys.servers and @@SERVERNAME return upper-case, while SERVERPROPERTY() returns lower-case? If true, that is very odd. I thought that @@SERVERNAME and SERVERPROPERTY('servername') both took the value from ``sys.servers`.
@SolomonRutzkyThanks for asking the questions but I don't think none of that matters. Seems like when you use agent to create a job SSMS is capitalizing the server name by english rules (for the sp_add_jobserver parameter) and that is conflicting with the server collation. If there is an option I'm not aware of to change that, please let me know.
@halid.sert Those questions might matter. You shouldn't be seeing casing differences in the output of those three methods of getting the Server Name. I was thinking that maybe the issue was with SSMS -> script generation as well, but that wouldn't explain why either @@SERVERNAME and/or SERVERPROPERTY('servername') had different casing. I will try to do a little more testing in the morning.
14:21
@SolomonRutzky No matter what the server name shows, lowercase or uppercase, SSMS gives the same output ('SAMPLE_INSTANCE'). It doesn't matter if the server name is written capitalized or not, letter 'I' will not match 'i' or 'İ'. This is not a critical problem as I have no problem with creating a job or anything else but I can't make any sense of the situation either.
@halid.sert I figured out the issue, why you are seeing different casing between @@SERVERNAME and SERVERPROPERTY('servername'), and a possible fix. Will post tomorrow as I'm out of time for today.
@SolomonRutzky Thanks, waiting :)
 
5 hours later…
19:16
@halid.sert Just updated my answer, please review..

  last day (17 days later) »