Search code examples
asp.netsql-serverdatabasedatabase-permissions

Why do i need to have create database permissions for asp.net web app?


I am building an ASP.NET, code-first web app. I am using a company owned database, and have crud permissions for tables within one database on this server. I do not believe I have "Create Database" permissions. I am running into issues publishing my web app. I can run everything locally, but when I publish the code on the company server I get errors like:

Format of the initialization string does not conform to specification starting at index 0. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error: 
 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 
[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
   System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +1742
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +191
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +136
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +75
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +35
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +241
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +78
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +116
   System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +104
   System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.SetConnectionString(DbConnection connection, DbConnectionPropertyInterceptionContext`1 interceptionContext) +434
   System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) +39
   System.Data.Entity.Internal.LazyInternalConnection.Initialize() +160
   System.Data.Entity.Internal.LazyInternalConnection.get_Connection() +16
   [Project].DBContext.Context..ctor() in C:\Users\[UserName]\Documents\[FilePath]\[Project]\DBContext\Context.cs:20
   [Project].Data_Manager.DataManager..ctor() in C:\Users\[UserName]\Documents\[FilePath]\[Project]\Data_Manager\DataManager.cs:15
   [Project].Controllers.HeaderController..ctor() in C:\Users\[UserName]\Documents\[FilePath]\[Project]\Controllers\HeaderController.cs:12

This error makes me believe I have an issue with my connection string. When using Unit Testing, I get the error:

An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code

Additional information: CREATE DATABASE permission denied in database 'master'.

I recently changed my context constructor from:

public Context() : base("[server_Name].[database_name]")
{}

to:

public Context() : base("[server_Name].[full_company_server_file_path]")
{}

And when I ran the solution locally, also got the "CREATE DATABASE permission denied in database 'master'" error.

For the record, my connection string is:

<connectionStrings>
      <clear />
    <add name="[server_Name].[database_name]" providerName="System.Data.SqlClient" connectionString="Data Source=[server_Name].[full_company_server_file_path];Initial Catalog=[database_name];Persist Security Info=True;User ID=userid;Password=password;MultipleActiveResultSets=True;Application Name=EntityFramework" />
< /connectionStrings>

My question is:

Why do I need Create Database Permissions in order for this all to work? And if that isn't the case, why do I keep getting this error? (No where in my code do I say create DB, nor should / can I).

Secondly, any suggestions as to fixing my connection string? I got this connectionString from database -> properties -> Connection String (so I feel like it's correct).

Thanks for all help / tips / explanations.

Using:

  • ASP.NET / Entity Framework / C#
  • Visual Studio 2015
  • SQL Server Management Studio 2014

Solution

  • SOLUTION

    For anyone curious, in the process of publishing (native Visual Studio action) the connection string was being garbled to:

    connectionString="$(ReplacableToken_[server_name].[database_name]-Web.config Connection String_0)" 
    

    I edited the published connection string to my real connection string and that fixed the problem.