我想首先更改由 ef 代码创建的整个数据库的排序规则,我尝试通过在创建后运行脚本来做到这一点,但它不起作用,
_dbContext.Database.Delete();
_dbContext.Database.CreateIfNotExists();
_dbContext.Database.ExecuteSqlCommand("ALTER DATABASE afi COLLATE French_CI_AI");
是否可以在创建数据库之前设置排序规则?
那是我得到的例外:
重置连接会导致与初始登录不同的状态。登录失败。用户“afi”登录失败。当前命令发生严重错误。结果,如果有的话,应该丢弃。
[SqlException (0x80131904):重置连接会导致与初始登录不同的状态。登录失败。
用户“afi”登录失败。当前命令发生严重错误。结果,如果有的话,应该被丢弃。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +84
System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel , Int32 超时, SqlInternalTransaction 事务, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) +1370
System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) +674
System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName) +547
System.Data.SqlClient.SqlInternalConnection.BeginTransaction(IsolationLevel iso) +18
System.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevelisolationLevel) +211
系统。 Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel 隔离级别) +155[EntityException:在提供程序连接上启动事务时发生错误。详情见内部异常。]
System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevelisolationLevel) +4298876
System.Data.EntityClient.EntityConnection.BeginTransaction() +10
System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) + 538 System.Data.Entity.Internal.InternalContext.SaveChanges() +218 Afi.Domain.Storage.AfiDbContext.SaveChanges() 在 c:\inetpub\wwwroot\afi\src\Domain\Storage\AfiDbContext.cs:190
Afi。 c:\inetpub\wwwroot\afi\src\Domain\Storage\EntitySession.cs:54 中的 Domain.Storage.EntitySession.Commit()
C:\inetpub\wwwroot\afi\src\Web\Controllers\CIController.cs:263
Afi.Web.Controllers.CIController.Seed(Boolean excludeSomeData) 在 c:\inetpub \wwwroot\afi\src\Web\Controllers\CIController.cs:89
lambda_method(Closure, ControllerBase, Object[]) +81
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 参数) +39 System.Web .Mvc.Async.<>c_ DisplayClass42.b _41() +34 System.Web.Mvc.Async.<>c_ DisplayClass39.b _33() +124 System.Web.Mvc.Async.<>c_ DisplayClass4f.b _49 () +837307 System.Web.Mvc.Async.<> c_DisplayClass4f.b2 parameters) +261
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
_49() +837307 System.Web.Mvc.Async.<>c_ DisplayClass37.b _36(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c_ DisplayClass2a.b _20() +33 System.Web.Mvc .Async.<>c_ DisplayClass25.b _22(IAsyncResult asyncResult) +837892
System.Web.Mvc.<>c_ DisplayClass1d.b _18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c_ DisplayClass4.b _3 (IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c_ DisplayClass4.b _3(IAsyncResult ar) +15 System.Web.Mvc.Controller。 EndExecute(IAsyncResult asyncResult) +51
System.Web.Mvc.<>c_DisplayClass8.b _3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c_ DisplayClass4.b _3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
System.Web。 CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288