Create login - domain name with '.'

  • Hi

    I'm trying to create a simple script to allow Network Service accout to access my database

    DECLARE @user NVARCHAR(50)

    SET @user = ABC.COM\ABC105$'

    DECLARE @SQL NVARCHAR(4000);

    SET @SQL = 'CREATE LOGIN [' + @user + '] FROM WINDOWS WITH DEFAULT_DATABASE=[master]'

    EXECUTE(@SQL);

    SET @SQL = 'CREATE USER [' + @user + '] FOR LOGIN ['+@user+'] WITH DEFAULT_SCHEMA=[dbo]'

    EXECUTE(@SQL);

    EXEC sp_addrolemember 'db_owner', @user

    GO

    The script fails with the message:

    Msg 15401, Level 16, State 1, Line 1

    Windows NT user or group 'ABC.COM\ABC105$' not found. Check the name again.

    if I just execute

    CREATE LOGIN ABC.COM\ABC105$ FROM WINDOWS WITH DEFAULT_DATABASE=[master]

    it says

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near '.'.

    How do I fix that?

    Thanks in advance

  • Hmmm I figured it out myself. The domain should not include the .com portion. Not clear why though

  • Just out of curiosity give this a try:

    CREATE LOGIN [ABC.COM]\ABC105$ FROM WINDOWS WITH DEFAULT_DATABASE=[master]

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply