Error: 18486 Login failed for user ‘sa’ because the account is currently locked out. The system administrator can unlock it.

here is the fix :

 

ALTER LOGIN sa WITH PASSWORD = ‘yourpass’ UNLOCK ;

GO

Of course you can also disable your policy

ALTER LOGIN sa WITH CHECK_POLICY = OFF;
ALTER LOGIN sa WITH CHECK_POLICY = ON;

Advertisements

map composite keys in Nhibernate

I have a legacy database where 2 columns are used in all the table create composite keys .

One of he error message which you may see :

must have same number of columns as the referenced primary key nhibernate

Solution :

Table1

ProjectID Version Project Name

Table 2

ProjectID Version Table2ID Name1

Table 3

ProjectID Version Table2ID Table3ID Name2

I have a common Composite key Project ID and Version from Table 1.




Mapping will look like this 



that’s it Smile


 


		
			

Create a search criteria in Nhibernate

I have a table ‘Post’ which has 3 columns :

ID

PostTitle

Tags

I want to write a search function in my repository  which search on “Tags” columns and  returns the posts list.

Here is the code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Criterion;
using VOITH.MyProject.Repository;
using VOITH.MyProject.Domain;
using VOITH.MyProject.Domain.Entities;

      public    IList GetPostByTags(string tags)
        {
            IList postList = GetNHBSession()
                       .CreateCriteria(typeof(Post))
                       .Add(Restrictions.Like("Tags",tags,MatchMode.Anywhere))
                       .List();

            return postList;

        }

Call Stored Procedure from Nhibernate

This may not the most efficient way to call stored procedure form Nhibernate using projects. But in my situation it first .In general when we uses  Nhibrnate there is almost no need to use. In my case I am mapping my application with Legacy Database so i need sometimes to call Stored Procedures from Nhibernate (though iI am trying my best to avoid this )..

So here is the simple way to use it pretty quickly :

1. Here is my Stored procedure

2. Here is the code snippet

Nhibernate error :Incorrect syntax near the keyword ‘Function’.

In our database sometimes we have column names which are actually the database keywords . If we want to access such columns from Nhibernate session  , it throws error message “Incorrect syntax near the word :’SOME DB KEYWORD’

 

Mapping :Before :

Mapping :After

Keeping database base reserve keyword in “[ ]”  brackets will fix the error message.

 

You can have look on all my previous Nhibernate posts

 

 

 

 

 

 

 

 

 

 

 

User Nhibernate with Legacy database

Topday we will talk little bit more about the Nhibernate topic. If you are new to this topic than

you can have look at  previous post

As its well accepted that Nhibernate is getting really (probably) first choice in applcation development
Its really easy to stary with Nhibernate for a new application development. You have more control
on your application  code and its db realtions .
Well  this doesnt go as smooth with Legacy DB as new application.

I have legacy database and it has many relations which could drive tyou crazy like anything .

Here in this post I will present a quick but very useful ways to map you WIERED realtions in Nhibernate using fluent Nhibernate.

Here is my small datamodel to explain this kinda of mapping

Data model

Mapping

 

Above mapping will create a mapping for the ToolLangTbl.

IF you notice int he mapping we have used CompositId to map such mappings.

Note :

In such cases always implement GetHashCode and Equal methods as below

 

 

If you still have some other wiered database relations and need help to map them ..I can try to help you in it.

Have a nice day ahead !!