HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMajor

Hyphen in my computer's name causing T-SQL error

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
errorsqlnamecausingcomputerhyphen

Problem

I’m a developer, not a DBA (which is showing, I’m afraid). I am trying to run Report Builder 3.0 with SQL Server 2014 Express on my home computer (named John-PC) and cannot run my reports.

I accidentally created a user/login combo of user = John-PC and login = John-PC\John. When I try to delete the entry with:

Drop Login John-PC\John


I get an error:


Incorrect syntax near '-'.

I think the problem is the hyphen in my computer's name.

  • Is there a way to get around the syntax error?



  • Is there another way to change or drop the user (I tried dropping from sys.server_principals but received an error that I couldn’t make ad hoc changes).



  • Can I give Report Builder a new user/login name somehow?



  • If none of the above, can I change the name of my computer to John_PC or will that create a host of other problems that I can’t even imagine?

Solution

When you have special characters in a name put []'s around it to let SQL know that it's an identifier. This is also how you manage special characters.

So in your case

Drop Login [John-PC\John]

Code Snippets

Drop Login [John-PC\John]

Context

StackExchange Database Administrators Q#116936, answer score: 22

Revisions (0)

No revisions yet.