Search This Blog

Executing Stored Procedure with Entity Framework

The following is the description of executing stored procedure with Entity Framework.
It describes two separate methods for reading data and inserting/updating data through stored procedure.

The following is the code.

1. Fetching data

static List ExecuteReadStoredProcedure(string storedProcName, Dictionary parameters)
        {
            using (var entityContext = new ImplementedDbContext())
            {
                var storedProcedureParams = GetStoredProcedureParameters(storedProcName, parameters);
                return entityContext.Database.SqlQuery(storedProcedureParams.StoredProcedureName,
                    storedProcedureParams.Parameters.ToArray()).ToList();              
            }
        }
2. Insert/Update

static int ExecuteInsertUpdateStoredProcedure(string storedProcName, Dictionary parameters)
        {
            using (var entityContext = new ImplementedDbContext())
            {
                var storedProcedureParams = GetStoredProcedureParameters(storedProcName, parameters);
                return entityContext.Database.ExecuteSqlCommand(storedProcedureParams.StoredProcedureName,storedProcedureParams.Parameters.ToArray());
            }
        }

3. Helper method
private static StoredProcedureParams GetStoredProcedureParameters(string storedProcedureName,Dictionary parameters) {
            StringBuilder query = new StringBuilder();
            var listOfParameters = new List();

            query.Append(storedProcedureName + " ");
            var count = 0;

            foreach (var p in parameters)
            {
                count++;
                query.Append(p.Key);
                if (count != parameters.Count)
                {
                    query.Append(",");
                }

                listOfParameters.Add(new SqlParameter(p.Key, p.Value));
            }

            return new StoredProcedureParams() {
                StoredProcedureName = query.ToString(),
                Parameters = listOfParameters
            };
        }

 4. Object Parameter

 class StoredProcedureParams {
            public string StoredProcedureName { get; set; }
            public List Parameters { get; set; }
        }

5.  Implementing Read
var dictParameters = new Dictionary();
                dictParameters.Add("@parameter1",value of parameter 1);
                dictParameters.Add("@parameter2",value of parameter 2);

                var readResponse = ExecuteReadStoredProcedure("Your-Read-StoredProcedureName", dictParameters);
5.1 Response Object
public class MyResponse
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

6. Implementing Insert/Update
var dictParametersCreateEmailTemp = new Dictionary();
                dictParametersCreateEmailTemp.Add("@parameter1","value");
                dictParametersCreateEmailTemp.Add("@parameter2", "value");
                dictParametersCreateEmailTemp.Add("@parameter3", "value");
                dictParametersCreateEmailTemp.Add("@parameter4", "value");

                var insertResponse = ExecuteInsertUpdateStoredProcedure("Your-Insert-StoredProcedureName", dictParametersCreateEmailTemp);
                

Deploying MVC4 website in IIS in Windows Server 2008 R2

First step, publish the website, and then deploy it in IIS.
Error: Forbidden error, directory listing disabled
Solution: Add [module runAllManagedModuleForAllRequests=true]   to web.config under system.webServer node.

 [system.webServer]
    [validation validateIntegratedModeConfiguration="false" /]
[modules runAllManagedModulesForAllRequests="true" /]
........
[system.webServer]


Another option, is not to use this method , instead use
[modules]
  [remove name="UrlRoutingModule-4.0" /]
  [add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /]
[/modules]

2. Error : Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.

Cause:  using EF 5.0 with .net 4
Since, i was not using EF, i removed it with Nuget. As i created the website with the default Internet application template, it came along with.

3. Oracle Dataaccess inconsistencies
Solution: copied all the oracle odp.net dll to bin.

Turn On/Off Hypervisor from Command Prompt

The necessity of switching the hypervisor aroused when working with virtual box and windows phone.
The hypervisor needs to be turned on when working with projects related to windows phone and needs to be turned off, when working with virtual box or vmware.

For the following purposes, run the command prompt with administrative privileges.

1. Check the status of the hypervisor

Command: "bcdedit /enum
will list the current settings of the 'Windows Boot Manager' & 'Windows boot loader'. Under 'Windows Boot Loader ', check for the setting of 'hypervisorlaunchtype' . It will be 'Off' if it is turned off and 'Auto', if it's turned On.

2. Turn Off the hypervisor
Command: "bcdedit /set hypervisorlaunchtype off"
And restart the system. 

3. Turn On the hypervisor
Command: "bcdedit /set hypervisorlaunchtype auto"
And restart the system


Implementing Oracle-ASP.NET-Provider in C #

Below is the process, how I have implemented the Oracle-ASP.NET-Provider within a ASP.NET web-application.

The first step is to install the latest version of the "Oracle Data Provider for .NET" from the oracle site

Then the next step is to create all the tables required for the Oracle-ASP.NET-Provider. For this, simply run the sql query from the file "InstallAllOracleASPNETProviders.sql" located at "C:\app\[the_computer_name]\product\11.2.0\client_4\ASP.NET\SQL" (considering you have accepted the default location for the installation).

1. Web.config

The web.config of the web-application looks like
[' < ' and ' > ' replaced by ' ( ' and ' ) ']
 Connection String
(add name="OraAspNetConnectionString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db_ip)(PORT=db_port))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = orcl)));User Id=user_db;Password=password_db;pooling=true;min pool size=9" providerName="Oracle.DataAccess.Client"/)
Membership Settings
(membership defaultProvider="OracleMembershipProvider")
      (providers)
        (clear/)
        (add name="OracleMembershipProvider" type="Oracle.Web.Security.OracleMembershipProvider, Oracle.Web, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342"
           connectionStringName="OraAspNetConnectionString" applicationName="" enablePasswordRetrieval="false"
           enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true"
           passwordFormat="Hashed" maxInvalidPasswordAttempts="10" minRequiredPasswordLength="7"
           minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""  /)
      (/providers)
   (/membership)

Profile Settings
    (profile)
      (providers)
        (clear/)
        (add name="OracleProfileProvider" type="Oracle.Web.Profile.OracleProfileProvider, Oracle.Web, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342"
           connectionStringName="OraAspNetConnectionString" applicationName="/"/)
      (/providers)
    (/profile)

Role Settings
    (roleManager enabled="true" defaultProvider ="OracleRoleProvider")
      (providers)
        (clear/)
        (add name="OracleRoleProvider" type="Oracle.Web.Security.OracleRoleProvider, Oracle.Web, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342"
           connectionStringName="OraAspNetConnectionString" applicationName="/" /)
        (!--(add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /)--)
      (/providers)
    (/roleManager)



 Here the OracleDataAccess.dll of version 2 is being used. 

2. Creating User

 protected void btnCreateUser_Click(object sender, EventArgs e)
        {
            try
            {
                Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtUserEmail.Text);
                txtUsername.Text = "User Created Successfully";
            }
            catch (Exception)
            {
             
                throw;
            }
         
        }

3. Creating Role

protected void btnCreateRole_Click(object sender, EventArgs e)
        {
            String roleName = txtRole.Text.Trim();
            try
            {
                if (!Roles.RoleExists(roleName))
                {
                    Roles.CreateRole(roleName);
                    txtRole.Text = "Role Created Successfully. " + txtRole.Text;
                }
                else
                {
                    txtRole.Text = "Role already exists. " + txtRole.Text;
                }
            }
            catch (Exception ex)
            {
                   throw;
            }
        }

4. Assigning Role to User

protected void btnAddRoleToUser_Click(object sender, EventArgs e)
        {
            try
            {
                Roles.AddUserToRole(txtUser.Text,txtRoleToAdd.Text);
                txtRoleToAdd.Text = "Role added";
            }
            catch (Exception)
            {
             
                throw;
            }
        }

5. User Login

protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
                {
                    FormsAuthentication.SetAuthCookie(txtUserName.Text, true);
                    txtUserName.Text = "success";
                }
                else {
                    txtUserName.Text = "fail";
                }
                 
             
            }
            catch (Exception)
            {
             
                throw;
            }
        }


SecurityNegotiationException WCF

Problem Faced:  created a WCF Service and hosted it in IIS. The client application could communicate with the Service iff it's in the same machine else throws SecurityNegotiationException Exception.

Solution:
Disabled the binding security,

Step1: Right click on the web.config in solution explorer, and select "Edit WCF Configuration"
Step 2: In the endpoint with wsHttpBinding, Create Binding configuration.
Step 3: under security tab, select Mode to None under General section.

ORA-01008: not all variables bound

Sometimes this might be because of the Data Access Provider.
I thought i would increase the data access performance in my application, SO, I changed the data-provider to Oracle.DataAccess.Client and the error occurred, could not figure out the exact reason though, but reverted back to System.Data.OracleClient, and everything worked as previous.

TODO: need to figure it out.

Me in 30 Seconds


A “me in 30 seconds” statement is a simple way to prepare to someone else a balanced understanding of who you are. It piques the interest of a listener who invites you to ‘tell something about yourself’ and provides a brief yet compelling answer to the “Why should I hire you?” question.
So, your ‘me in 30 seconds’ statement should include:

# 1. A brief personal introduction that includes your career objectives or the type of position you want.

# 2. Three or four specific accomplishments that you meet or exceed the requirement of that position.

# 3. A few character traits or adaptive skills that set you apart from typical applicants.

When networking, end your statement with probing questions.

Second and subsequent job interviews


More and more companies are using multiple job interviews to select employees these days. The objective of these interviews is to carry out a more detailed evaluation and will typically assess:

@1 Intellectual capacity –To determine the intelligence of the applicant.

@2 Personality or psychological summary – To determine the character or professionalism.

@3 Motivation – To understand the determination and perseverance.

@4 Management ability – To assess the ability to manage workload and co-employees.

Jingle Bells Lyrics, Christmas Song + video

Artist: Jingle Bells lyrics
Title: Jingle Bells    

Dashing through the snow
In a one horse open sleigh
O'er the fields we go
Laughing all the way
Bells on bob tails ring
Making spirits bright
What fun it is to laugh and sing
A sleighing song tonight

Oh, jingle bells, jingle bells
Jingle all the way
Oh, what fun it is to ride
In a one horse open sleigh
Jingle bells, jingle bells
Jingle all the way
Oh, what fun it is to ride
In a one horse open sleigh

A day or two ago
I thought I'd take a ride
And soon Miss Fanny Bright
Was seated by my side
The horse was lean and lank
Misfortune seemed his lot
We got into a drifted bank
And then we got upsot

Oh, jingle bells, jingle bells
Jingle all the way
Oh, what fun it is to ride
In a one horse open sleigh
Jingle bells, jingle bells
Jingle all the way
Oh, what fun it is to ride
In a one horse open sleigh yeah

Jingle bells, jingle bells
Jingle all the way
Oh, what fun it is to ride
In a one horse open sleigh
Jingle bells, jingle bells
Jingle all the way
Oh, what fun it is to ride
In a one horse open sleigh

Girls Generation : The Boys, English Version + lyrics (US SM Town)







Lyrics

 I can tell you're lookin at me I know what you see
Any closer and you'll feel the heat
You don't have to pretend that you didn’t notice me
Every look will make it hard to breathe
Bring the boys out (yeah you know)
Bring the boys out (we bring the boys out we bring the boys out yeah)
Bring the boys out
Soon as I step on the scene
I know that they'll be  watching me watching me (get up)
I'ma be the hottest in this spot
There ain't no stopping me (That's funny) stopping me
I know life is a mystery I'm gonna make history
I'm taking it from the start
Call all emergency I'm watching the phone ring
I'm feeling this in my heart (my heart)
Bring the boys out.
Girls' Generation make you feel the heat
And we're doin it we can't be beat
(Bring the boys out)
We're born to win Better tell all your friends
Cuz we get it in You know the girls
(Bring the boys out)
Wanna know my secrets But no I'll never tell
Cuz I got the magic touch and I'm not trying to fail
That's right (yes fly high!) And I (I) (you fly high!) Can't deny
I know I can fly
I know life is a mystery I'm gonna make history
I'm taking it from the start Call all emergency
I'm watching the phone ring I'm feeling this in my heart (my heart)
Bring the boys out.
Girls' Generation make you feel the heat
And we're doin it we can't be beat
(Bring the boys out)
We're born to win Better tell all your friends
Cuz we get it in You know the girls
(Bring the boys out)
Girls bring the boys out!
I wanna dance right now We can show em how the girls get down
Yes we go for more than zero Number one
everyone should know Check this out
All'a (all the) Boys, All'a(all the) Boys want my heart Better know
how to rock and don't stop
Oh gee we make it so hot Girls generation we won't stop
Bring the boys out
It's not a fantasy This is right for me Living it like a star
Can't get the best of me I'ma be
what I wanna be This is deep in my heart
I can tell you're lookin at me
I know what you see Any closer
and you'll feel the heat (Just Bring the boys out)
You don't have to pretend that
you didn't notice me Every look will make it hard to breathe (Bring The Boys out)
Cuz the girls bring the boys out Girls bring the boys out
Girls bring the boys out Girls bring the boys out
Girls' Generation make em feel the heat
And we're doin it we can’t be beat (Bring the boys out)
We're born to win Better tell all your friends
Cuz we get it in You know the girls
(Bring the boys out)


New Loadshedding shedule frome tuesday poush, 10 hours loadshedding

Are you in Right Career: Know Your Scores With Career QUIZ !!!


Are you wondering if you are in the right job or career? Nothing is more draining or less motivating than staying in a position because of inertia of fear of the unknown.
Wouldn’t it be better to find out and decide whether or not to take action? Then you can plan what steps you need to take before you start a new search. 

The career quiz below will help you judge whether your career is on track. Answer yes or no to the following questions. Each yes answer counts one point. Compare your point total to the scoring key.

>1. I look forward to going to work.

>2. I talk about my work in a positive way.

>3. I have mentored a junior colleague or want to.

>4. I don’t fear layoff or termination, as I have a portfolio of skills to draw upon.

>5. I know how to network and market myself to my best advantage.

>6. People seek me out to ask career advice.

>7. I’ve achieved a good balance in my life between work and play.

>8. Money is not the driving force in deciding my next career move.

>9. I am learning from, and enjoy working with, my team or co-workers.

>10. If self-employed, I have a network of professionals who I can turn to for advice or encouragement.

>11. I feel excited about my upcoming projects, as they engage me creatively.

>12.When I face a setback at work. I am able to recover quickly as I have a reserve of energy/self-confidence.

>13. I am self-motivated and generate much of my “to do” list at work.

>14. I have a well-written, up-to-date resume.

>15. I feel positive about my future job prospects.

>16. I know where I’d like to be in five years.

>17. I know where I’d like to be in one year.

>18. I’m being compensated fairly.

>19. I respect my boss.

>20. I am able to work productively with my co-workers (or clients), even those who are difficult.

>21. I know how to deal effectively with office politics. 

>22. I have the training I need to do my job well.

>23. My boss is supportive and has provided me with opportunities to learn and grow.

>24. I’m working with a company (or client) that has integrity.

>25. I attend professional/trade association meetings to stay up-to-date in my field.


Scoring KEY
21-25 Points
Wow. Congratulations, you love your work! Never stop improving. Consider taking seminar or learning a new language.
16-20 Points
You’re doing well. This is a very good score. Speak with your boss about new opportunities or challenges you might undertake.
11-15 Points
You’ doing okay, but there’s room for improvement. Join a professional organization to grow your network and get information about other opportunities that may exist in your industry.
6-10 Points
Yes, there’s work to do. Tap into your network of colleagues and friends to discuss other career areas of interest. Seek out a mentor to get support and a broader perspective.
0-5 Points
You are not alone. It takes time and desire to find the right livelihood. Use this quiz as a starting point to pinpoint the changes. Consider taking a career assessment and/or working with a career coach to help you clarify your career goals. Know that many have successfully transitioned to careers and jobs they love.

INTERVIEW POSER: WHY DO YOU WANT TO WORK HERE?


 
You are facing the interview and things are going great. Just when you think it is about to finish, the interviewer asks, “what are the reasons you want to work here?” If you are not prepared for this question ‘it could be devastating. This is why it is imperative that you be prepared for this. How? By researching in the company, in its past, in its present, in its plans for future. Though the answer is seemingly simple, like you want to work there because it is a good place to work in and you can do a good job there, it actually is not so simple to put it across in such a way that it should boost your chances to land the job.

When you answer this question you should keep in mind that the aim of this interview is to find the best fit candidate for the job. Remember that everything that you say should center on that aspect. Hence, when you answer this question you need to describe how your past experience, skills and expertise made you think that you could be an effective and efficient member of the company’s team.

For example, if you are a good marketing strategist, you could mention how your past marketing techniques and negotiating skills have brought you success in your field, and how you think that such skills would be sharpened by the advanced know- how of the future organization where you could get better results. Always use your answer to show that you know about the company, its products and requirements and you are ready to do what it takes to promote that goal. For this purpose you need to research well the company, goals, and mission, vision its past five year’s financial performance and future plans. A person who is well informed about the company is very much interested in it. This is the message that goes to the interviewer and this is the message that s/he should get it.

Employers of big company’s not only love to hear their praises, they expect it. Be sure that you include a bit of subtle flattery in your answer; however the flattery should be subtle as otherwise it will look cheap and backfire.

You can always say that the company has always been your dream company but did not apply till you thought that you have achieved a certain amount of skill set and experience so you could contribute to the growth and future of the company. You could say that till that time, thought you searched for opportunity, you never got a job that would exactly fit to your skills set as well as the present job and so on.

Keep in mind that whatever you say should focus on your fit with the company and not vice-versa. The interviewer should be left with the impression that you have done your homework and are convinced that you can be a useful part of the team. Project yourself as a willing and deserving candidate who can promote the aim and goals of the company. And that should be your answer, a person who want to be part of the company because they believe they can be part of its growth.

Is this post helpful, Response via Comment BOX..!!