为什么我需要为asp.net web app创建数据库权限?
我正在构建一个ASP.NET,代码优先的web应用程序。我使用的是一个公司所有的数据库,并且对该服务器上一个数据库中的表具有crud权限。我认为我没有“创建数据库”权限。我在发布web应用程序时遇到问题。我可以在本地运行所有内容,但当我在公司服务器上发布代码时,会出现如下错误:为什么我需要为asp.net web app创建数据库权限?,asp.net,sql-server,database,database-permissions,Asp.net,Sql Server,Database,Database Permissions,我正在构建一个ASP.NET,代码优先的web应用程序。我使用的是一个公司所有的数据库,并且对该服务器上一个数据库中的表具有crud权限。我认为我没有“创建数据库”权限。我在发布web应用程序时遇到问题。我可以在本地运行所有内容,但当我在公司服务器上发布代码时,会出现如下错误: Format of the initialization string does not conform to specification starting at index 0. Description: An
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]")
{}
致:
当我在本地运行该解决方案时,还出现了“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>
我的问题是:
为什么我需要创建数据库权限才能使这一切正常工作?
如果不是这样的话,为什么我总是得到这个错误?(在我的代码中没有我说的创建DB的地方,我也不应该/可以)
第二,关于修复我的连接字符串有什么建议吗?我从数据库->属性->连接字符串中得到了这个连接字符串(所以我觉得它是正确的)
谢谢你的帮助/提示/解释
使用:
- ASP.NET/Entity Framework/C#
- Visual Studio 2015
- SQL Server管理工作室2014
生产环境中的应用程序就是这样工作的,流程也是这样实施和遵循的,很少有例外。解决方案 对于任何好奇的人来说,在发布(本机Visual Studio操作)的过程中,连接字符串被篡改为:
connectionString="$(ReplacableToken_[server_name].[database_name]-Web.config Connection String_0)"
我将已发布的连接字符串编辑为真实的连接字符串,这解决了问题。您可以手动在该服务器上创建数据库吗?我的意思是使用提供的凭证直接登录到SQLServerManagementStudio上的SQLServer。我不确定是否可以,但我不想这样做。这是一家非常大的公司,我不想弄乱这样的事情。如果您可以创建任何测试数据库并在以后删除它,然后发现您是否有权限,那就更好了。好的-我尝试创建一个新数据库,但得到了“在数据库“master”中拒绝创建数据库权限”(Microsoft SQL Server,错误:262).这意味着你有权限问题。正确的?您可以在获得数据库管理员的权限后重试,或者不要尝试在“我的代码”中创建数据库。我创建表,这是允许我在服务器中执行的。我能够创建表、创建存储过程、更新表、删除表等。我在SQLServerManagementStudio中成功地做到了这一点&在本地代码中。当我试图从发布的开发环境中访问数据库时,我遇到了一些问题——即使只是select语句也会使代码崩溃。本地数据库服务器和企业数据库服务器不一样。错误表示“创建数据库权限被拒绝”。这意味着EF正在尝试首先创建数据库,因为它在开发服务器上不存在。所以,您首先需要获得DBA在那里创建的数据库,还需要请求用户的模式所有者权限,这是连接字符串的一部分,但这种安排只适用于开发环境。对于暂存和生产环境,根本不允许使用db所有者角色。您的应用程序将只允许执行数据选择、更新、删除、运行存储过程或应用程序正常运行所需的其他操作。在stage和prod环境中,模式更改bu应用程序肯定是不被允许的。但是,我没有使用本地数据库-只使用开发服务器数据库。我使用服务器上的现有数据库,创建了模式,并使用EF在服务器dev db上创建了所有表。我的应用程序只调用表上的crud操作。那么真正的问题是为什么EF要尝试创建新的数据库。更改上下文的构造函数有什么原因吗?您还可以共享[server\u Name].[full\u company\u server\u file\u path]的示例值吗?
connectionString="$(ReplacableToken_[server_name].[database_name]-Web.config Connection String_0)"