nhibernate for ASP.NET - Could not add assembly ORM_dscnew - nhibernate

I am new to nhibernate. I am facing the following problem:
Exception thrown: 'NHibernate.MappingException' in NHibernate.dll
NHibernate.MappingException: Could not add assembly ORM_dscnew ---> System.IO.FileNotFoundException: Could not load file or assembly 'ORM_dscnew' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
at viroffice.ORM_sessionf.Init() in D:\GDrive\Projects\VirOffice\viroffice\DataObjects\ORM_sessionf.vb:line 7
While executing the function:
Private Shared sFactory As NHibernate.ISessionFactory
Private Shared Sub Init()
Dim config As New NHibernate.Cfg.Configuration()
Try
config.AddAssembly("ORM_dscnew")
sFactory = config.BuildSessionFactory()
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex)
Exit Sub
End Try
End Sub
While executing the above function, I am getting the error.
ORM_dscnew.hbm.xml:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns = "urn:nhibernate-mapping-2.2" namespace = "viroffice.DataObjects" assembly = "viroffice">
<class name = "ORM_dscnew" table="dsc_new">
<id name = "new_id">
<generator class = "native"/>
</id>
<property name = "vnm" />
<property name = "vcn_name" />
<property name = "vref" />
<property name = "vcn_per" />
<property name = "vcn_no" />
<property name = "vcn_email" />
<property name = "vcn_email1" />
<property name = "vrmks" />
<property name = "vstatus" />
<property name = "vapp_id" />
<property name = "vmob_ver" />
<property name = "vchg_code" />
</class>
</hibernate-mapping>
Kindly advice what needs to be done?

Using AddAssembly("ORM_dscnew") result in a call to System.Reflection.Assembly.Load("ORM_dscnew"). And in your case, the .Net Framework is unable to find your assembly and yields a FileNotFoundException.
NHibernate just wrap it in a MappingException. The root trouble is your assembly being not found (or one of its dependencies...). Microsoft docs states the assembly name should be a long name, and your code only supply the simple name, so maybe that is your issue.
Anyway, personally, I favor adding an assembly by getting it from a type contained in it. Of course, this implies your factory will need a reference to such a type.
config.AddAssembly(typeof(ATypeInORM_dscnew).Assembly);

Related

ORA-00955 Erorr

Im trying to make migration from visual Studio. Im building a project with Razor pages ASP.NET Core With Oracle database and when i make the migration comes this error:
2020-03-17 22:32:15.351073 ThreadID:1 (ERROR) OracleRelationalCommand.Execute() : Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-00955: Es gibt bereits ein Objekt mit diesem Namen
at OracleInternal.ServiceObjects.OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)
at OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, OracleConnection connection, OracleLogicalTransaction& oracleLogicalTransaction, Boolean isFromEF)
at Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
at Oracle.EntityFrameworkCore.Storage.Internal.OracleRelationalCommandBuilderFactory.OracleRelationalCommandBuilder.OracleRelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)

The data reader is incompatible with the specified 'IAPD_DBModel.Table_Price

I'm developing a Web API using ASP.NET Web API 2 and Entity Framework to access the database. I call my SQL Server stored procedures which is very simple and should be returning one column as follows:
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getnationalities]
AS
BEGIN
SET NOCOUNT ON;
SELECT DISTINCT
Table_Price.Price_Nationality AS 'name'
FROM
Table_Price;
END
and here is my vb code :
Namespace Controllers
Public Class NationalityController
Inherits ApiController
Public Function getcountries() As IHttpActionResult
Using entities As IAPD_DBEntities = New IAPD_DBEntities()
Return Ok(entities.getnationalities.ToList)
End Using
End Function
End Class
End Namespace
and here is the error I'm getting from postman
{
"message": "An error has occurred.",
"exceptionMessage": "The data reader is incompatible with the specified 'IAPD_DBModel.Table_Price'. A member of the type, 'Price_PK_ID', does not have a
corresponding column in the data reader with the same name.",
"exceptionType": "System.Data.Entity.Core.EntityCommandExecutionException",
"stackTrace": " at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.GetMemberOrdinalFromReader(DbDataReader storeDataReader, EdmMember member, EdmType currentType, Dictionary`2 renameList)\r\n at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.GetColumnMapsForType(DbDataReader storeDataReader, EdmType edmType, Dictionary`2 renameList)\r\n at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary`2 renameList)\r\n at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateFunctionImportStructuralTypeColumnMap(DbDataReader storeDataReader, FunctionImportMappingNonComposable mapping, Int32 resultSetIndex, EntitySet entitySet, StructuralType baseStructuralType)\r\n at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.FunctionColumnMapGenerator.System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.IColumnMapGenerator.CreateColumnMap(DbDataReader reader)\r\n at System.Data.Entity.Core.Objects.ObjectContext.MaterializedDataRecord[TElement](EntityCommand entityCommand, DbDataReader storeReader, Int32 resultSetIndex, ReadOnlyCollection`1 entitySets, EdmType[] edmTypes, ShaperFactory`1 shaperFactory, MergeOption mergeOption, Boolean streaming)\r\n at System.Data.Entity.Core.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, ReadOnlyCollection`1 entitySets, EdmType[] edmTypes, ExecutionOptions executionOptions)\r\n at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass47`1.<ExecuteFunction>b__46()\r\n at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass47`1.<ExecuteFunction>b__45()\r\n at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ExecutionOptions executionOptions, ObjectParameter[] parameters)\r\n at ProjectDataAccess.IAPD_DBEntities.getnationalities() in C:\\Users\\Junaida\\documents\\visual studio 2015\\Projects\\WebApplication7\\ProjectDataAccess\\DataAccessModel.Context.vb:line 5552\r\n at WebApplication7.Controllers.NationalityController.getcountries() in C:\\Users\\Junaida\\documents\\visual studio 2015\\Projects\\WebApplication7\\WebApplication7\\Controllers\\NationalityController.vb:line 13\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
What I really target is to get a dataset or array of nationalities
Sorry, I don't know Entity Framework but I can get a list of data from a stored procedure.
Dim lstNationalities As New List(Of String)
Using cn As New SqlClient.SqlConnection("Your connection string")
Using cmd As New SqlClient.SqlCommand With {
.Connection = cn,
.CommandType = CommandType.StoredProcedure,
.CommandText = "getnationalities"}
cn.Open
Using dr As SqlClient.SqlDataReader = cmd.ExecuteReader
Do While dr.Read
lstNationalities.Add(dr.GetString(0))
Loop
End Using
End Using
End Using

Connection Automatically Timedout (Session Timeout)

I am currently working on an application in which the user logins to view/edit multiple types of report, so other users can see what changes have been made. But sometimes when the user is going to a new page the session automatically timeouts.
My code is:
Function Check_Access(ByVal strModule As String) As String
Dim drAccess As SqlClient.SqlDataReader, strUser As String
GetNetworkName()
strUser = HttpContext.Current.Session("LOGON_USER")
drAccess = SqlHelper.ExecuteReader(strConnOASIS, "Oasis.dbo.p_RPT_Check_Accessibility", strModule, strUser)
If drAccess.HasRows Then
If drAccess.Read() Then
Return drAccess.GetString(0)
End If
End If
drAccess.Close()
Return "0"
End Function
The source error is:
Line 45: strUser = HttpContext.Current.Session("LOGON_USER")
Line 46:
Line 47: drAccess = SqlHelper.ExecuteReader(strConnOASIS, "Oasis.dbo.p_RPT_Check_Accessibility", strModule, strUser) //Error
Line 48:
Line 49: If drAccess.HasRows Then
And lastly the Stack Trace:
[InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.]
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +445
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +132
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +195
System.Data.SqlClient.SqlConnection.Open() +122
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) +412
Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(String connectionString, String spName, Object[] parameterValues) +442
OasisInclude.GlobalFunctions.Check_Access(String strModule) in E:\Danish\VSO\OasisRedesign\Dev\Oasis\OasisInclude\GlobalFunctions.vb:47
Residential.Residential.Page_Load(Object sender, EventArgs e) in E:\Danish\VSO\OasisRedesign\Dev\Oasis\Oasis\Residential\Residential.aspx.vb:56
System.Web.UI.Control.OnLoad(EventArgs e) +109
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3321
You are never closing the data reader if it returns data. All those open data readers are holding your database connections causing the error.
To fix it, change the code to:
Function Check_Access(ByVal strModule As String) As String
Dim drAccess As SqlClient.SqlDataReader, strUser As String
GetNetworkName()
strUser = HttpContext.Current.Session("LOGON_USER")
drAccess = SqlHelper.ExecuteReader(strConnOASIS, "Oasis.dbo.p_RPT_Check_Accessibility", strModule, strUser)
Try
If drAccess.HasRows Then
If drAccess.Read() Then
Return drAccess.GetString(0)
End If
End If
Finally
drAccess.Close()
End Try
Return "0"
End Function

Entity Framework v5.0 Exception 'From' is a reserved keyword and cannot be used as an alias, unless it is escaped

I use EntityFrameWork v5.0, EntityDataSource control.
In code I set SQL query, but when I open page after compilation I get exception. How can I fix it?
Code:
entryListDs.CommandParameters.Add(new Parameter("subId", DbType.Int32, Common.CurrentUserID.ToString()));
entryListDs.CommandParameters.Add(new Parameter("typeId", DbType.Int32, ((int)MessageType.Wall).ToString()));
entryListDs.CommandText = #"SELECT
m.ID,
m.To,
m.Subject,
m.BodyHtml,
m.CreationDate,
m.New,
m.TypeID
FROM
message AS m
JOIN subscription AS s
ON m.From = s.ObjectID
WHERE s.SubscriberID = #subId and m.TypeID = #typeId
ORDER BY m.CreationDate DESC";
Exeption when I open page:
'From' is a reserved keyword and cannot be used as an alias, unless it is escaped. Near line 12, column 6.
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.Data.EntitySqlException: 'From' is a reserved keyword and cannot be used as an alias, unless it is escaped. Near line 12, column 6.
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:
[EntitySqlException: 'From' is a reserved keyword and cannot be used as an alias, unless it is escaped. Near line 12, column 6.]
System.Data.Common.EntitySql.CqlLexer.MapUnescapedIdentifier(String symbol) +8073331
System.Data.Common.EntitySql.CqlLexer.MapIdentifierOrKeyword(String symbol) +57
System.Data.Common.EntitySql.CqlLexer.Accept_83() +36
System.Data.Common.EntitySql.CqlLexer.yylex() +386
System.Data.Common.EntitySql.CqlParser.yylex() +16
System.Data.Common.EntitySql.CqlParser.yyparse() +132
System.Data.Common.EntitySql.CqlParser.internalParseEntryPoint() +101
System.Data.Common.EntitySql.CqlParser.Parse(String query) +148
System.Data.Common.EntitySql.CqlQuery.Parse(String commandText, ParserOptions parserOptions) +41
System.Data.Common.EntitySql.CqlQuery.CompileCommon(String commandText, Perspective perspective, ParserOptions parserOptions, Func`3 compilationFunction) +84
System.Data.Common.EntitySql.CqlQuery.CompileQueryCommandLambda(String queryCommandText, Perspective perspective, ParserOptions parserOptions, IEnumerable`1 parameters, IEnumerable`1 variables) +100
System.Data.Objects.EntitySqlQueryState.Parse() +8608663
System.Data.Objects.EntitySqlQueryState.GetResultType() +4
System.Data.Objects.ObjectQuery.GetResultType() +58
System.Web.UI.WebControls.EntityDataSourceQueryBuilder`1.BuildBasicQuery(ObjectContext context, Boolean computeCount) +108
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelectTyped(DataSourceSelectArguments arguments, Creator qbConstructor) +355
System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +606
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
System.Web.UI.WebControls.ListView.PerformSelect() +102
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
System.Web.UI.WebControls.ListView.CreateChildControls() +52
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033
If you use keywords or special symbols in column names, then brackets are required. Just put column name in square brackets:
ON m.[From] = s.ObjectID
It says right there in your Exception: From is a reserved keyword.
In your query you have ON m.From = s.ObjectID. You need to rename your From column to something else.

SSAS database backup fails with the error 3239837698

When I run XMLA query to backup SSAS database
<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" Transaction="false" >
<Backup xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Object>
<DatabaseID>MyDB</DatabaseID>
</Object>
<File>D:\SSAS\OLAP\Backup\MyDB.abf</File>
<AllowOverwrite>true</AllowOverwrite>
</Backup>
</Batch>
It runs for an hour, creates backup file, and gives me an error:
<return xmlns="urn:schemas-microsoft-com:xml-analysis">
<results xmlns="http://schemas.microsoft.com/analysisservices/2003/xmla-multipleresults">
<root xmlns="urn:schemas-microsoft-com:xml-analysis:empty">
<Exception xmlns="urn:schemas-microsoft-com:xml-analysis:exception" />
<Messages xmlns="urn:schemas-microsoft-com:xml-analysis:exception">
<Error ErrorCode="3239837698" Description="Server: The operation has been cancelled." Source="Microsoft SQL Server 2008 Analysis Services" HelpFile="" />
</Messages>
</root>
</results>
</return>
Log says:
`Microsoft.AnalysisServices.Xmla.XmlaException: Server: The operation has been cancelled.
at Microsoft.AnalysisServices.Xmla.XmlaClient.CheckForSoapFault(XmlReader reader, XmlaResult xmlaResult, Boolean throwIfError)
at Microsoft.AnalysisServices.Xmla.XmlaClient.CheckForError(XmlReader reader, XmlaResult xmlaResult, Boolean throwIfError)
at Microsoft.AnalysisServices.Xmla.XmlaClient.SendMessage(Boolean endReceivalIfException, Boolean readSession, Boolean readNamespaceCompatibility)
at Microsoft.AnalysisServices.Xmla.XmlaClient.SendMessageAndReturnResult(String& result, Boolean skipResult)
at Microsoft.AnalysisServices.Xmla.XmlaClient.Execute(String command, String properties, String& result, Boolean skipResult, Boolean propertiesXmlIsComplete)
at Microsoft.SqlServer.Management.Smo.Olap.SoapClient.ExecuteStatement(String stmt, StatementType stmtType, Boolean withResults, String properties, String parameters, Boolean restrictionListElement, String discoverType, String catalog)
at Microsoft.SqlServer.Management.Smo.Olap.SoapClient.SendCommand(String command, Boolean withResults, String properties)
at OlapEvent(SCH_STEP* pStep, SUBSYSTEM* pSubSystem, SUBSYSTEMPARAMS* pSubSystemParams, Boolean fQueryFlag)Microsoft.AnalysisServices.Xmla.XmlaException: Server: The operation has been cancelled.
`
I am not sure if backup is good.
Try looking at ForceCommitTimeout.