2017-01-23 59 views
0

我正在构建一个ASP.NET,代码优先的Web应用程序。我正在使用公司拥有的数据库,并且对该服务器上的一个数据库中的表具有欺诈权限。我不相信我有“创建数据库”权限。我遇到发布我的网络应用程序的问题。我可以在本地运行一切,但是当我发布公司服务器上的代码,我得到这样的错误:为什么我需要为asp.net web应用程序创建数据库权限?

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 

这个错误让我相信,我有我的连接字符串的问题。当使用单元测试,我得到的错误:

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'. 

最近,我改变了我的上下文构造来自:

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

到:

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

而当我跑的解决方案在本地,也得到了“CREATE DATABASE permission denied in database 'master'”错误。

为了记录在案,我的连接字符串是:

<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> 

我的问题是:

为什么我需要为了让这一切工作创建数据库的权限? 如果情况并非如此,为什么我一直得到这个错误? (没有在我的代码中,我说创建数据库,也不应该/我可以)。

其次,有关修复我的连接字符串的任何建议?我从数据库 - >属性 - >连接字符串得到了这个connectionString(所以我觉得它是正确的)。

感谢您的所有帮助/提示/解释。

使用:

  • ASP.NET /实体框架/ C#
  • 的Visual Studio 2015年
  • SQL Server Management Studio中2014
+0

您可以在该服务器上手动创建数据库吗?我的意思是通过登录提供的凭据直接到SQL管理工作室的SQL服务器。 – Amir

+0

我不确定我是否可以,但我不认为。这是一家非常大的公司,我不想这样做。 – swallis1

+0

如果您可以创建任何测试数据库并在稍后将其删除并发现您有权限,则会更好。 – Amir

回答

0

SOLUTION

对于任何人好奇,在出版的过程中(本机Visual Studio中的动作)的连接字符串正在乱码到:

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

我编辑公布的连接字符串我的真实连接字符串,并解决了问题。

0

有没有什么可以做,除了在这里得到您的应用程序在db服务器上执行此类活动的权限在大型组织中不太可能发生。

对此的最佳解决方案不是将数据库创建操作作为Web应用程序发布过程的一部分。

当然,组织的策略不允许应用程序以master db权限运行。

将数据库创建活动留给正在管理数据库服务器和数据库的DBA。他们将有必要的访问和权限来执行此类操作。他们将创建数据库并运行脚本以使您的数据库可供应用程序使用。

创建一个脚本,该脚本将创建包括表,视图,存储过程,函数,键,索引等在内的整个数据库结构,并引发票据或RFC或遵循所需的任何过程,以便使用目标结构创建数据库服务器。让您的应用程序只处理数据,而不用担心数据库的创建和更新。

这就是生产环境中的应用程序的工作方式,这就是过程如何实现,并遵循极少数例外情况。

+0

我不试图在我的代码中创建数据库。我创建了表格,我可以在服务器上执行这些表格。我能够创建表格,创建存储过程,更新表格,删除表格等。我已经在SQL Server Management Studio和代码中成功完成了本地操作。当我尝试从已发布的开发环境中访问数据库时遇到了问题 - 即使只是select语句崩溃了代码。 – swallis1

+0

本地数据库服务器和企业数据库服务器不一样。该错误说“创建数据库权限被拒绝”。这意味着EF试图首先创建数据库,因为它在开发服务器上不存在。因此,您首先需要获取由DBA在那里创建的数据库,并请求作为连接字符串的一部分的用户的架构所有者权限 –

+0

但是,安排仅适用于开发环境。对于分段和生产环境,数据库所有者角色根本不被允许。您的应用程序将被允许仅执行数据选择,更新,删除,运行存储过程或应用程序正常朗姆酒所需的其他内容。在阶段和产品环境中,模式更改bu应用程序完全不被允许。 –

相关问题