Quantcast
Viewing all articles
Browse latest Browse all 7205

How to use XPO in ASP.NET MVC3 application (Razor)

This example demonstrating a simple ASP.NET MVC3 application using XPO as Data Access Layer.

See also: How to use XPO in an ASP.NET MVC application

Question Comments

Added By: TPS Programmer at: 11/3/2014 2:38:52 AM    

how to convert this syntaks

@model IEnumerable<CustomerViewModel>
@Html.Partial("IndexPartial", Model);

into vb syntax ?

Added By: TPS Programmer at: 11/3/2014 2:40:10 AM    

almost forget, because in VB source code, index.cshtml still in C#, not in VBHTML

Added By: Anthony (DevExpress Support) at: 11/3/2014 5:01:27 AM    

Hi,

The code would be as follows:

[VB.NET]
@ModelType IEnumerable(Of CustomerViewModel) @Html.Partial("IndexPartial", Model)

As for the example, we will correct the syntax as soon as possible.

Added By: Larry Kingsbury at: 5/26/2015 11:16:52 AM    

It sure would be nice if you would upgrade your examples to the current version of MircoSoft and DevExpress products.  When I tried to run the Example from here in VS 2013 using MVC 4, it had to convert to the current version and then I had to play with references and I finally ended up with this stack dump:
System.TypeInitializationException was unhandled by user code
 HResult=-2146233036
 Message=The type initializer for 'XpoHelper' threw an exception.
 Source=DevExpressMvcApplication
 TypeName=XpoHelper
 StackTrace:
      at XpoHelper.GetNewUnitOfWork()
      at DevExpressMvcApplication.Controllers.BaseXpoController`1.CreateSession() in c:\Visual Studios\DevExpressMvcApplication\Controllers\BaseXpoController.cs:line 18
      at DevExpressMvcApplication.Controllers.BaseXpoController`1..ctor() in c:\Visual Studios\DevExpressMvcApplication\Controllers\BaseXpoController.cs:line 10
      at DevExpressMvcApplication.Controllers.CustomersController..ctor()
 InnerException: DevExpress.Xpo.DB.Exceptions.UnableToOpenDatabaseException
      HResult=-2146233088
      Message=Unable to open database. Connection string: 'data source=.;initial catalog=XPOMVXExampleEditable;integrated security=sspi;'; Error: 'System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
  at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
  at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
  at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, SqlAuthenticationMethod authType)
  at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
  at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
  at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
  at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken)
  at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
  at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
  at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
  at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
  at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
  at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
  at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
  at System.Data.SqlClient.SqlConnection.Open()
  at DevExpress.Xpo.DB.MSSqlConnectionProvider.CreateDataBase(SqlConnection conn)
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:2,State:0,Class:20'
      Source=DevExpress.Xpo.v14.2
      StackTrace:
           at DevExpress.Xpo.DB.MSSqlConnectionProvider.CreateDataBase(SqlConnection conn)
           at DevExpress.Xpo.DB.MSSqlConnectionProvider.CreateDataBase()
           at DevExpress.Xpo.DB.ConnectionProviderSql..ctor(IDbConnection connection, AutoCreateOption autoCreateOption)
           at DevExpress.Xpo.DB.MSSqlConnectionProvider..ctor(IDbConnection connection, AutoCreateOption autoCreateOption)
           at DevExpress.Xpo.DB.MSSqlConnectionProvider.CreateProviderFromString(String connectionString, AutoCreateOption autoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
           at DevExpress.Xpo.DB.DataStoreBase.QueryDataStore(String providerType, String connectionString, AutoCreateOption defaultAutoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
           at DevExpress.Xpo.XpoDefault.GetConnectionProvider(String connectionString, AutoCreateOption defaultAutoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
           at DevExpress.Xpo.XpoDefault.GetDataLayer(String connectionString, XPDictionary dictionary, AutoCreateOption defaultAutoCreateOption, IDisposable[]& objectsToDisposeOnDisconnect)
           at DevExpress.Xpo.XpoDefault.GetDataLayer(String connectionString, AutoCreateOption defaultAutoCreateOption)
           at XpoHelper.UpdateDatabase() in c:\Visual Studios\DevExpressMvcApplication\Helpers\XpoHelper.cs:line 48
           at XpoHelper..cctor() in c:\Visual Studios\DevExpressMvcApplication\Helpers\XpoHelper.cs:line 12
      InnerException: System.Data.SqlClient.SqlException
           HResult=-2146232060
           Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
           Source=.Net SqlClient Data Provider
           ErrorCode=-2146232060
           Class=20
           LineNumber=0
           Number=2
           Server=""
           State=0
           StackTrace:
                at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
                at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
                at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, SqlAuthenticationMethod authType)
                at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
                at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
                at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
                at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken)
                at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
                at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
                at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
                at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
                at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
                at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
                at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
                at System.Data.SqlClient.SqlConnection.Open()
                at DevExpress.Xpo.DB.MSSqlConnectionProvider.CreateDataBase(SqlConnection conn)
           InnerException: System.ComponentModel.Win32Exception
                HResult=-2147467259
                Message=The system cannot find the file specified
                ErrorCode=-2147467259
                NativeErrorCode=2
                InnerException:

Can you post an already migrated version so I don't have to waste more hours?


Viewing all articles
Browse latest Browse all 7205

Trending Articles