我目前正在尝试将 ASP.NET MVC 4 网站从 postgreSQL 迁移到 MS SQL(然后使用 SQL Azure)。该网站与 pgsql 完美配合。我预计只需更改连接字符串和数据库驱动程序就足够了,但我收到一条错误消息:
NHibernate.HibernateException: Incorrect syntax near the keyword 'Public'. ---> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'Public'.
请注意,我们使用 NHibernate Castle 进行数据库交互。这是显示 NHibernate 配置的 web.config 部分:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=folke;Integrated Security=SSPI;</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="Folke" />
</session-factory>
当我调用此方法时触发错误:
public static void Install()
{
new SchemaExport(CurrentConfiguration).Execute(true, true, false);
}
这是完整的错误消息:
NHibernate.HibernateException:关键字“公共”附近的语法不正确。---> System.Data.SqlClient.SqlException:关键字“Public”附近的语法不正确。在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 在 System.Data.SqlClient.TdsParser. 在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常,布尔 breakConnection,操作
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) 在 System.Data.SqlClient.TdsParser。在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(字符串方法名,布尔异步,Int32 超时)在 System.Data.SqlClient.SqlCommand 的 TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean&dataReady)。1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at NHibernate.Tool.hbm2ddl.SchemaExport.ExecuteSql(IDbCommand cmd, String sql) at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action
1 scriptAction, Boolean export, Boolean throwOnError, TextWriter exportOutput, IDbCommand statement, String sql) at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action1 scriptAction, Boolean export, Boolean justDrop, IDbConnection connection, TextWriter exportOutput) at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action
1 scriptAction, Boolean export, Boolean justDrop) --- 内部异常堆栈跟踪结束 -- - 在 NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action1 scriptAction, Boolean export, Boolean justDrop) at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop) at FolkeLib.BaseDataAccess.Install() in e:\Documents\GitHub\Folke\FolkeLib\BaseDataAccess.cs:line 36 at Folke.Models.Installer.Install() in e:\Documents\GitHub\Folke\Folke\Models\Installer.cs:line 22 at Folke.Controllers.InstallerController.Index() in e:\Documents\GitHub\Folke\Folke\Controllers\InstallerController.cs:line 20 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 参数) 在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) 在 System.Web.Mvc.ControllerActionInvoker.<> c_DisplayClass15 .<>c _DisplayClass17.b__14() 在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary
2 个参数)在 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName);