none
SQL Express 2008 R2 - CREATE DATABASE permission denied in database 'master'. (Microsoft SQL Server, Error: 262)

    Question

  • So, we have an application that we've written to leverage SQL Express 2008 R2 - which our setup installs on the command line using the following instructions:

    http://msdn.microsoft.com/en-us/library/ms144259.aspx

    The code that does the installation can be found here:

     

    //Path to the SQL Installation files 

    string strSQLPath = Application.StartupPath + "\\Install_Support_Files\\SQL_86\\Setup.exe"; 

    //If we're on a 64-bit OS use the 64 bit setup

    if (Wow.Is64BitOperatingSystem == true)

    {

    strSQLPath = Application.StartupPath + "\\Install_Support_Files\\SQL_64\\Setup.exe";

    }

    //Set our path to the setup

    string SQLfn = strSQLPath;

    //Our command line parameters

    string SQLp = "/QS /ACTION=Install /FEATURES=SQL /INSTANCENAME=QuietDB  /IACCEPTSQLSERVERLICENSETERMS /ADDCURRENTUSERASSQLADMIN";

    //Setup our process

    ProcessStartInfo psiSQL = new ProcessStartInfo(SQLfn, SQLp);

    Process SQLprocess = new Process();

    //try to run it

    try

    {

    SQLprocess = System.Diagnostics.Process.Start(psiSQL);

    }

    catch (Exception ex)

    {

    MessageBox.Show(ex.Message);

    }

    //Chill while the installer runs 

    SQLprocess.WaitForExit();

    This seems to work ok. After this is complete, we connect to the database and that seems ok, too.

    On some systems, though when we try to run the SQL to create the database, we get:

    CREATE DATABASE permission denied in database 'master'. (Microsoft SQL Server, Error: 262)

    It's not on all systems that this occurs, but we see it enough that it's become an issue and we lost a sale today because the customer had this problem. 

    My questions are:

    1. Why didn't this work: /ADDCURRENTUSERASSQLADMIN ?

    2. Is there a better way to go about doing the installation?

    3. We've moved to SQL Express 2008 because it's pretty much impossible to get SQL Express 2005 to install on XP SP3 now. We did the msi cleanup utility bit to get MSXML 6.0 off the machines before installing for a bit, but the msi cleanup utility is no longer available, so that's hosed. Should I even be continuing to develop with SQL Express or would something like MySQL be a better option for a desktop application?

    Thanks for any replies/suggestions!

     

     

    Thursday, October 7, 2010 8:51 PM

Answers

  • Hi joehinder,

     

    Why didn't this work: /ADDCURRENTUSERASSQLADMIN ?

    Did you mean you can log in SQL Server with this windows account and this account is not sysadmin server role?

    This issue might be caused by that the operation adding this login to sysadmin server role is blocked by some software. Since this operation requires accessing the system, if there is any Anti-Virus software, this operation might be blocked.

     

    If we want to add this login to sysadmin server role while there is no valid login which is sysadmin server role, we could use single-user mode to perform this operation. Please see the steps below:

    1.       Stop SQL Server service and add parameter indicating the SQL Server to start in Single-User mode
    a) Run "SQL Server Configuration Manager" from "Start Menu | Microsoft SQL Server 2005(or 2008) | Configuration Tools"
    b) Click "SQL Server Services" in the left, and then double-click "SQL Server(instance name)"
    c) In the dialog, click "Advanced" in the top, in the properties add ";-m" to the end of list in the "Startup Paramaters" option
    d) Click "OK"

    2.       Start SQL Server service

    3.       Run "sqlcmd.exe" and add this login to sysadmin server role
    please type the following script:
    USE MASTER
    CREATE LOGIN <login name>
    GO
    sp_addsrvrolemember '<login name>', 'sysadmin'
    GO
    EXIT

    4.       Stop SQL Server service, remove ";-m" you add in the step 1

    5.       Start SQL Server service

    6.       Connect to SQL Server with the login you created

     

    Note:

    ·         If you use an Operating System with User Account Control(UAC), please run "sqlcmd.exe" with "Run As Administrator"

    ·         There is no blank between ";" and "-m"

     

    For more information about Single-User Mode, please refer to “-m” option in this link: http://msdn.microsoft.com/en-us/library/ms190737.aspx

     

    Is there a better way to go about doing the installation?

    I would like to recommend that you perform this operation after closing all other applications temporarily. Meanwhile if you want to install SQL Server Express on an operating system with User Account Control (UAC), please run this application with “Run as Administrator”.

    Besides Microsoft has provided a white paper about Embedding SQL Server 2008 Express in an Application, there is much useful information in this white paper, I would like to recommend that you read it. Please see this link: http://msdn.microsoft.com/en-us/library/dd981032%28v=SQL.100%29.aspx

    Though it is for SQL Server 2008 Express, it also could be used for SQL Server 2008 R2 Express.

     

    If anything is unclear, please let me know.


    Regards,
    Tom Li
    Friday, October 8, 2010 8:17 AM
    Moderator

All replies

  • Hi joehinder,

     

    Why didn't this work: /ADDCURRENTUSERASSQLADMIN ?

    Did you mean you can log in SQL Server with this windows account and this account is not sysadmin server role?

    This issue might be caused by that the operation adding this login to sysadmin server role is blocked by some software. Since this operation requires accessing the system, if there is any Anti-Virus software, this operation might be blocked.

     

    If we want to add this login to sysadmin server role while there is no valid login which is sysadmin server role, we could use single-user mode to perform this operation. Please see the steps below:

    1.       Stop SQL Server service and add parameter indicating the SQL Server to start in Single-User mode
    a) Run "SQL Server Configuration Manager" from "Start Menu | Microsoft SQL Server 2005(or 2008) | Configuration Tools"
    b) Click "SQL Server Services" in the left, and then double-click "SQL Server(instance name)"
    c) In the dialog, click "Advanced" in the top, in the properties add ";-m" to the end of list in the "Startup Paramaters" option
    d) Click "OK"

    2.       Start SQL Server service

    3.       Run "sqlcmd.exe" and add this login to sysadmin server role
    please type the following script:
    USE MASTER
    CREATE LOGIN <login name>
    GO
    sp_addsrvrolemember '<login name>', 'sysadmin'
    GO
    EXIT

    4.       Stop SQL Server service, remove ";-m" you add in the step 1

    5.       Start SQL Server service

    6.       Connect to SQL Server with the login you created

     

    Note:

    ·         If you use an Operating System with User Account Control(UAC), please run "sqlcmd.exe" with "Run As Administrator"

    ·         There is no blank between ";" and "-m"

     

    For more information about Single-User Mode, please refer to “-m” option in this link: http://msdn.microsoft.com/en-us/library/ms190737.aspx

     

    Is there a better way to go about doing the installation?

    I would like to recommend that you perform this operation after closing all other applications temporarily. Meanwhile if you want to install SQL Server Express on an operating system with User Account Control (UAC), please run this application with “Run as Administrator”.

    Besides Microsoft has provided a white paper about Embedding SQL Server 2008 Express in an Application, there is much useful information in this white paper, I would like to recommend that you read it. Please see this link: http://msdn.microsoft.com/en-us/library/dd981032%28v=SQL.100%29.aspx

    Though it is for SQL Server 2008 Express, it also could be used for SQL Server 2008 R2 Express.

     

    If anything is unclear, please let me know.


    Regards,
    Tom Li
    Friday, October 8, 2010 8:17 AM
    Moderator
  • Hi joehinder,

     

    Why didn't this work: /ADDCURRENTUSERASSQLADMIN ?

    Did you mean you can log in SQL Server with this windows account and this account is not sysadmin server role?

    This issue might be caused by that the operation adding this login to sysadmin server role is blocked by some software. Since this operation requires accessing the system, if there is any Anti-Virus software, this operation might be blocked.

     

    If we want to add this login to sysadmin server role while there is no valid login which is sysadmin server role, we could use single-user mode to perform this operation. Please see the steps below:

    1.       Stop SQL Server service and add parameter indicating the SQL Server to start in Single-User mode
    a) Run "SQL Server Configuration Manager" from "Start Menu | Microsoft SQL Server 2005(or 2008) | Configuration Tools"
    b) Click "SQL Server Services" in the left, and then double-click "SQL Server(instance name)"
    c) In the dialog, click "Advanced" in the top, in the properties add ";-m" to the end of list in the "Startup Paramaters" option
    d) Click "OK"

    2.       Start SQL Server service

    3.       Run "sqlcmd.exe" and add this login to sysadmin server role
    please type the following script:
    USE MASTER
    CREATE LOGIN <login name>
    GO
    sp_addsrvrolemember '<login name>', 'sysadmin'
    GO
    EXIT

    4.       Stop SQL Server service, remove ";-m" you add in the step 1

    5.       Start SQL Server service

    6.       Connect to SQL Server with the login you created

     

    Note:

    ·         If you use an Operating System with User Account Control(UAC), please run "sqlcmd.exe" with "Run As Administrator"

    ·         There is no blank between ";" and "-m"

     

    For more information about Single-User Mode, please refer to “-m” option in this link: http://msdn.microsoft.com/en-us/library/ms190737.aspx

     

    Is there a better way to go about doing the installation?

    I would like to recommend that you perform this operation after closing all other applications temporarily. Meanwhile if you want to install SQL Server Express on an operating system with User Account Control (UAC), please run this application with “Run as Administrator”.

    Besides Microsoft has provided a white paper about Embedding SQL Server 2008 Express in an Application, there is much useful information in this white paper, I would like to recommend that you read it. Please see this link: http://msdn.microsoft.com/en-us/library/dd981032%28v=SQL.100%29.aspx

    Though it is for SQL Server 2008 Express, it also could be used for SQL Server 2008 R2 Express.

     

    If anything is unclear, please let me know.


    Regards,
    Tom Li


    GREAT !!, It's Working. Now can create databases in SQL 2008 Express with Windows 7

    Thanks a lot !!

    Friday, August 5, 2011 9:46 PM