2

我使用 Entity Framework 5 使用 ASP.NET MVC 4 创建了一个站点。我将它连接到 SQL Server 数据库。完成我的项目后,我决定使用 Network Solutions 发布并托管它。Network Solutions 还托管了一个我尝试连接的 SQL Server 数据库。当我尝试访问该站点时,出现以下错误:

数据库“master”中的 CREATE DATABASE 权限被拒绝。

我也无法通过 SQL Server Management Studio 登录数据库

我联系了 Network Solutions,他们的解释是:

“有一个脚本反复用于删除这个数据库,我们已经代表你重新创建了它。”

这是堆栈跟踪:

System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1754082
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5295874
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout) +280
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +405
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +160
System.Data.SqlClient.<>c__DisplayClassa.<DbCreateDatabase>b__7(SqlConnection conn) +33
System.Data.SqlClient.SqlProviderServices.UsingConnection(SqlConnection sqlConnection, Action`1 act) +92
System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act) +384
System.Data.SqlClient.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +276
System.Data.Objects.ObjectContext.CreateDatabase() +84
System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext) +8
System.Data.Entity.Database.Create() +42
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +385
System.Data.Entity.Internal.<>c__DisplayClass5.<PerformDatabaseInitialization>b__3() +19
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +164
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +110
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +185
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +27
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +58
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
System.Linq.Queryable.Where(IQueryable`1 source, Expression`1 predicate) +63
JourneymensAid.Controllers.HomeController.FillSession(String email) in HomeController.cs:319
JourneymensAid.Controllers.HomeController.Index() in HomeController.cs:28
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +182
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
System.Web.Mvc.Controller.ExecuteCore() +105
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +87
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9630364
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

现在看一些相关的代码片段:

从我的MarketInitializer.cs班级:

public class MarketInitializer : CreateDatabaseIfNotExists<MarketContext>
{
    protected override void Seed(MarketContext context)

我的连接字符串web.config

<add name="MarketContext" 
     connectionString="Data Source=<ip address of db>;Initial Catalog=<db name>;User Id=<user name> ;Password=<password>;" 
     providerName="System.Data.SqlClient"/>

在做了一些研究之后,我发现要删除以下行Global.asax.cs

Database.SetInitializer<MarketContext>(new MarketInitializer());

我删除了它,我仍然得到同样的错误。我已经用谷歌干了,我没有解决方案。

什么可能会删除我的数据库?

4

2 回答 2

0

如果您的数据库已经存在,您可以在此处调用Database.SetInitializer<MarketContext>(null); 更多信息:http: //msdn.microsoft.com/en-us/data/jj200620

于 2013-10-04T23:43:32.037 回答
0

查看正在应用的迁移脚本或在此处发布。我敢打赌,种子正在运行的某些东西正在删除该数据库。请记住,EF 迁移几乎包含您在模型中更改的所有内容。

Update-Database -Script -SourceMigration: $InitialDatabase

或者

Update-Database -Script -SourceMigration: 0

将为您提供迁移脚本。

于 2015-09-15T14:25:22.287 回答