ASP.NET Change Membership Provider to MySql

Background

This started out as an experiment with ASP.NET MVC.  When you create a MVC project it auto-creates the membership functionality for you.  By default the membership provider it uses is the local MSSQL Express instance.  This is great but I host my sites with a shared provider and MSSQL Express is not available.  I could use MSSQL but am limited to the number of databases I can create, or I can use MySql.  So I started looking for a MySql membership provider solution.  I found an article by Nolan Bailey and he covers everything but I wanted to be a little more explicit about the steps.

Required Software

Before you start you need to download:
MySql – I recommend the Community Server Edition (Why? Because it is Free.)
MySql Connector/Net — for connecting to MySql from .NET (Get the latest version)
MySql Admin – GUI to manage your MySql instance (Not necessary but it helps to visually verify everything is working properly)

Process Steps

  1. Install MySql ( I downloaded the .MSI installer.  I like this because it registers all the services, .DLL’s, etc.)
    1. Launch the MSI
    2. Follow the onscreen instructions
    3. Remember the password you enter, you will need it.
  2. Install MySql Connector/Net (Again I like the .MSI because it registers everything for me)
    1. Launch the MSI
    2. Follow the onscreen instructions
    3. I choose the complete install
  3. Install MySql Admin
    1. Launch the MSI
    2. Follow the onscreen instructions
  4. Create a New Project in VS 2008
    1. Click File – New Project
    2. Set the Name and Location Information
    3. Click OK
  5. Create the reference to the required DLL files
    1. In “Solution Explorer” expand your project and find “References”
    2. Right Click “References” and click “Add Reference…”
    3. Click on the “Browse” tab
    4. Browse to “C:\Program Files\MySQL\MySQL Connector Net 6.0.4\Assemblies”  (This will be different depending on the version of MySql Connector/Net you downloaded)
    5. Select “MySql.Data.dll”
    6. Click OK
    7. Expand “References”
    8. Right-Click on MySql.Data and choose properties
    9. Change Copy Local to true
    10. Right Click “References” and click “Add Reference…”
    11. Click on the “Browse” tab
    12. Browse to “C:\Program Files\MySQL\MySQL Connector Net 6.0.4\Assemblies”  (This will be different depending on the version of MySql Connector/Net you downloaded)
    13. Select “MySql.Web.dll”
    14. Click OK
    15. Expand “References”
    16. Right-Click on MySql.Web and choose properties
    17. Change Copy Local to true
  6. Modify the Web.config
    1. Create your connection string
      1. It should look something like: <add name="MySqlApplicationServices" connectionString="Server=localhost;Database=<Membership Security Schema>;User ID=root;Password=<from step 1.3>;" providerName="MySql.Data.MySqlClient" />
        1. Replace <Membership Security Schema> with the name of the database you want to use for your project
        2. Replace <from step 1.3> with your actual password
    2. Copy settings from machine.config to web.config
      1. Click File – Open File…
      2. Browse to x:\Windows\Microsoft.NET\Framework\<version>\config\machine.config (<version> will depend on version of .NET you are targeting.  In the case of 2 and 3.5 it is v2.0.50727)
      3. Select machine.config and click “Open”
      4. Locate the section <system.web>
      5. Copy the following sections from your machine.config to your web.config <system.web> section
        1. <Membership>
        2. <roleManager>
        3. <profile>
    3. Update the web.config settings
      1. You will need to update the connectionStringName for each provider to correspond to the connection string names in your web.config
        1. Example: <add name="MySQLProfileProvider" type="MySql.Web.Profile.MySQLProfileProvider, MySql.Web, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" connectionStringName="MySqlApplicationServices" applicationName="/" />
      2. Add autogenerateschema=”true” to the membership provider string for your MySql instance
        1. Example: <add connectionStringName="MySqlApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="MySQLMembershipProvider"  type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.0.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" autogenerateschema="true" />
  7. Change  your provider settings
    1. On the “Project” Menu select “ASP.NET Configuration”
    2. It will launch a web browser
    3. Click on the “Provider” tab
    4. Choose the link “Select a different provider for each feature (advanced)”
    5. Select the MySql providers they will be listed as the name=”” attribute from their configuration strings in the web.config
    6. Close the web browser
  8. Setup the Database (Schema) – If you don’t setup the database you will get the error “Invalid schema or catalog specified for provider” or something similar when you run your application.

You have now setup MySql as your Membership provider.  The first time your application attempts to use the membership functionality the proper tables will be created automatically.

Migrating the database to your production environment is well documented so I won’t go into that here.  Just remember to update your connection string.

I hope this helps.

16. June 2009 16:23 by Duane | Comments (8) | Permalink

What happened to Employer Loyalty?

Granted, most employees now move companies about every 3 to 6 years so you could pose the question “What happened to Employee Loyalty?”  Well, I can tell you…

It went to the same place as pension funds, retirement funds, employer provided insurance ( all forms Health, Life, Vision, and Dental ).  These were replaced with things like “profit sharing”, “401K contributions”,  “Employer subsidized Insurance”.  So now employees are giving half-hearted devotion to employers and are moving on to the next better thing (whatever that means, and it is different for each employee).  Long gone is the idea that a company will take care of you and so you can work for and retire with one company. (Nothing new, I know)

As more and more of the benefits that our grandparents received disappeared for our parents, we became skeptical that employers cared about employees at all.  We watched as our parents scrambled to start private retirement accounts, paid more for health care, and now face very uncertain post-retirement lives.

We, hopefully, started 401K’s, IRA, and Roth IRA’s either with an employer sponsored program or privately in our twenties.  The recent down turn in the economy erased about half of mine but hey, I still have a few years and hopefully it recovers before I want to retire.  Now employers are dropping even the limited contributions they were making to our future.  Companies are scaling back on Employer contributions to 401K’s and Profit Sharing programs citing that it is a cost savings measure to get through the current economic crisis.  That implies that once the crisis is over the benefits will come back.  Wake up!  The benefits wont come back.

Most employer sponsored 401K programs have a 5 year vesting schedule, it is my belief that this is a main reason most employees hang in for 5 years.  It is generally accepted that the best way to get a pay increase is to find a new employer, and it creates some excitement about the new situation, it doesn’t seem like the same old day-to-day as the last job (even if it is).  With minimal or non-existent employer contributions to retirement accounts we are stuck with private accounts with no vesting schedule (no reason to stay with the employer).  I predict that employees tenure with companies will drop in the future to 2 to 3 years instead of the 3 to 5 years currently.  Why?  When you take away a 3% match in 401K your just gave your employees a 3% cut in pay because they now have to make up the difference towards their retirement out of their own pockets.  Your employees will need to make more money, and like I said above, new employer = more money.

Employers ask yourselves what is the higher turnover rate going to cost you in recruiting, training, lost productivity, lost client relationships, and lost knowledge?  Is it really worth cutting these benefits?  I think these maneuvers are very short sighted, and will cost you more in the long run.

18. March 2009 11:51 by Duane | Comments (1) | Permalink

What did you say?

Today I was writing a reply to an email where we were discussing how a process would be completed.  After we had come to a common ground this statement ran though my head,  “So let it be written, So let it be done” which was immediately followed by “Make it so” it actually took me several tries to come up with a response that didn’t require knowing the reference.

So, I thought, “How often to I talk in stolen verbiage?”, and how often does the other person not know what I am saying because they don’t get the reference.  Now imagine that you don’t speak English or didn’t grow up with much exposure to popular culture.  I have put together a little list of phrases I use (or used) and the source, “do you understand the words that are coming out of my mouth?”

“Make it so” – Jean-Luc Picard
”So let it be written. So let it be done.” – Pharaoh Rameses II
”Git’r Done” – Larry the Cable Guy
”FUBAR” – US military.
”SNAFU” – US military. I think my dad used this one.
”I feel the need… the need for speed” – ‘Maverick’ and ‘Goose’
”Watchin’ NASCAR n’ drinkin’ beer” – Bubba J.
”Say hello to my little friend” – ‘Scarface’ Tony Montana 
“Buffer Overflow” – Computer term.
”Buffer Underrun” – Computer term.

How often do you use jargon, literary, or pop-culture phrases that other people might not understand?

What common phases have I missed?

18. February 2009 14:19 by Duane | Comments (0) | Permalink

2009 Economic Stimulus Package --- Or NOT!

What in the world are the leaders of the USA thinking?  I was trying not to put a political rant up but…

Government manipulation of the forces of the free market in a capitalistic economy always have long-lasting, latent, negative effects on the market.

THE END!

Forgive me if I miss something or get something in the wrong order, I am not an economist.  I am a computer programmer, but I do have a degree in business so I understand, if somewhat imperfectly, economic forces.

I have actually downloaded and read, as much as I can stomach, the American Recovery and Reinvestment Act of 2009. (2009 Economic Stimulus Package) As of this posting you can access this through the Library of Congress at H.R.1

The formal title is:

AN ACT
Making supplemental appropriations for job preservation and creation, infrastructure investment, energy efficiency and science, assistance to the unemployed, and State and local fiscal stabilization, for the fiscal year ending September 30, 2009, and for other purposes.

My reaction to this statement:
supplemental appropriations – Great this means spending in addition to the already deficit Federal Government budget.
job preservation and creation – How is the government going to preserve and create jobs.  Does this mean that the government is going to be hiring?  Face it the government can’t force a company to hire people, so if the government is going to create jobs it is in the public sector.
infrastructure investment – What? There are two kinds of infrastructure the government can invest in: (1) more government jobs (2) government maintained roads, buildings, cars, and equipment.
energy efficiency and science – That’s vague.  “We here-by resolve to turn the lights off at night!”
assistance to the unemployed – OK, people have lost jobs not because of their own actions but because of the economy.  We can throw a little their way to feed their kids, but I am not feeding the Octuplets forever.
State and local fiscal stabilization – Great! More government spending on government.
fiscal year ending September 30, 2009 – Well at least they put an end to when the money can be spent.  Oh wait, no they didn’t these programs have funding that is available to use until into the next decade.

Division A starts with the statement “That the following sums are appropriated, out of any money in the Treasury not otherwise appropriated, for the fiscal year ending September 30, 2009, and for other purposes, namely:”.  This kills me, “we want money that you have laying around not being used or earmarked for anything else” come on that has to be a joke, right? 

As I read on through the appropriations of the bill it occurred to me that none of this is going to lead to more jobs being created. 

They are paying farmers who did not have insurance on crops that they lost.  I guess the farmers could then pay off the loans they have for this year but they will still be “gun shy” of taking out the same loans next year and will cut back on production because they can’t sell off what they produced this year. 

They are putting more money into the digital TV converter box coupon program.  How is this going to help stimulate the economy?  Wouldn’t it be better to give coupons toward a new TV?  Wait, The US doesn’t produce TV’s that money would exit the US economy faster than my 401K disappeared.  But I don’t think the digital converter boxes are US products either, so I guess it doesn’t matter.

Putting more money into WIC (I am not saying that is bad), but I have done the math on this and with government programs like this there is no incentive to get off the program.  Most of the time the program cuts the recipient off before they reach a level where they can support their family as well off the program as they do on it.

Increasing the amount that the oversight agencies can increase benefits for welfare and social security programs per year.  These benefits are for people who are already out of the workforce and don’t count toward the unemployment rate because they are not able to, don’t want to, or are retired from working.

Giving money to NASA and Scientific research.  I am all for space exploration and scientific discovery.  There are many things including the computer I am typing on right now that would not exist except for government spending on research.  The problem is that it takes years for civilian applications of government technology to become affordable and the economy needs help now.

Giving money to the military.  OK.  I grew up in a family supported by a member of the US Air Force.  I have no problem with protecting my freedoms and doing anything to for the armed forces.  But, it shouldn’t be part of a economic stimulus package.  Again, it looks like the government is hiring.

Giving money to telecommunication companies to deliver broadband internet access to rural areas not yet serviced.  How is that going to help? 

States are going to get money to be used to bring their education programs funding up to 2008 levels.  Well, I haven’t heard of a lot of teachers being laid off, so I guess this will help them keep their jobs, but it is not going to give states any money toward expanding those programs.  Hmm, I think we shorted our kids on this one, and I think it may have actually created jobs if expansion of programs were allowed.

Then of course they have to setup a special oversight committee that gets funds needed to carryout the duties and responsibilities of the committee.  No actual dollar amount specified just the blank check.

Reading through the tax breaks only makes me mad.  There is a 4% tax cut for income over $70,000 or $140,000 married.  Businesses get tax cuts.  Any tax cuts I might receive don’t show up until next years taxes.  How is that going to encourage me to spend now.

Moving on to what I think might have worked…

What caused the economic down turn? 

A. Greenspan was praised for decreasing interest rates and spurring on a growing economy.  By lowering interest rates it encouraged people to borrow more money, and spent it.  Housing costs shot up as people who previously could not afford housing got into the market.  Demand went up so prices went up.  Investors, primarily banks, came up with riskier and riskier loan programs to get people into the house buying market.  Interest only loans, ARM’s of every shape and form, balloon loans all geared to get Marry and John Citizen into a house they could barely afford.  Some people were smart and didn’t leverage the buying power to the max but instead chose moderate houses that they could afford and traditional mortgages.  Then something happened, more houses were available than people looking for houses the market flipped on its ear and house prices started to go down.  Home construction didn’t stop because the bubble hadn’t completely burst.

Speculators in the commodities markets, specifically crude oil, started to buy oil futures with no intent of actually taking delivery of the oil.  Refining companies in order to protect their production levels bought large amounts of futures, further driving the price up.  This increase in price had to be passed on to customers so pump prices increased.  Suddenly, it wasn’t as cheap to ship items, the shipping industry was losing money.  Growers of perishable foods were forced to pay higher and higher costs to get their goods to market.  They had no choice but to pass the costs on to retailers who passed it on to customers. 

Now there where forces pushing consumers to spend less because it costs more to drive to work and eat. We quit buying large cars, we didn’t drive on that summer vacation, we shortened the vacations we did take.  We had to, our house’s value was starting to soften, we were mortgaged to the hilt and some of us had to fold under the pressure.  Consumers started to declare bankruptcy and get foreclosed on.  Banks started to lose money to lend to business.  Demand for gasoline went down as we adjusted our habits.  The price at the pump started to go down as a result of the less demand.  Oil futures didn’t look so appealing and the price of crude fell.  Speculators started to lose money.  Less spending, lower prices and less profit. Corporations started to feel the pinch and slowed down operations and laid off some workers.  And the spiral was in full force.

So how do you reverse it?

If you look at what started the whole mess it was when the pseudo-government known as the Federal Reserve Banking System lowered interest rates in fear that they would slow down the economy.  The housing market became artificially inflated.  They lowered interest rates too far, so now they can’t go down anymore when it might actually help.  The Federal Reserve Banking System needs to be opened up to public scrutiny.  The federal reserve chair person should not be elected to perpetual terms and should serve one 6 year term that starts on odd numbered years so that they never coincide with presidential elections or term lengths.

In order for the housing market to recover the federal government needs to let banks that made bad loans or invested in the commodities markets fail.  Let the stronger banks and credit unions consume these company’s assets and debts.  Sell them off piecemeal, that is what the government would do if I became insolvent and owed back taxes.  Then provide money to the banks that survive to provide refinance options to get people out of the non-conventional loans.  These banks have proven that they have good business practices.  I think longer term, 40, 50, and 60 year loan programs should be made available only for refinances out of current non-traditional loans.  New home and current traditional home loans would not be eligible for the longer term traditional loans.  This would prevent the houses from being foreclosed.  Theses houses will not end up on the market continuing to drive housing prices down.  Some stability will return to the housing markets.

Commodities trading needs to be regulated so that speculators can not artificially inflate the cost of commodities futures.  Banks and other financial institutions should be banned from investing in the commodities markets and let those businesses that actually consume those goods compete over the supply.  I can’t refine oil why should I own futures in oil?  or Beans, or hogs, or corn?  Let these markets regulate themselves again and get the speculators out!

The biggest problem is that the confidence of the worlds consumers is gone.  I have no good way to restore that.  I know bigger government and deficit spending wont help, but neither will higher taxes.

I am one of the people who is cutting back, trying to reduce my debt.  I wont feel good about the economy for a while and will only be making necessity purchases.  Any tax refund or stimulus check I receive will be going toward getting me out of debt, and that will be my mantra for the next few years.

I am still glad I live in the USA and I think we are still far better off than the people I have seen in my trips to China.  Good luck to you all and I hope to see you on the other end of the ride.

12. February 2009 15:48 by Duane | Comments (2) | Permalink

asp.net onClick not executing

I am filing this in the category of WTF (What Terrible Functionality). 

We have all created forms with many different input controls that post back information we then process in some way.  Our users have come to expect that when they hit enter while filling out the form that it will trigger the submission of the form, and we usually do the processing through the onClick event of the submit button. 

I was creating a very simple form 1 textbox and a button that was to be used for a search page for an Intranet site.  During testing I discovered that sometimes this worked just fine and other times it didn’t work at all.  I could not figure out from users descriptions what they were doing differently.  I started paying special attention to the testers and how they were submitting the search criteria.  One user would type the search string then press tab, highlighting the submit button then press enter.  Another user would type the search criteria then with the mouse click the submit button.  It worked properly for both of these users.  But, one user would enter the search criteria then with the cursor still in the text box would hit enter.  It wouldn’t work.

This is an issue with the way that IE submits form data in the special circumstance of one textbox control on a form and the user pressing Enter while the textbox has focus.  4 Guys from Rolla have an excellent article that explains this behavior Enter and the Button Click Event.  Basically, IE does not submit the buttonID – Value pair for the submit button in this special circumstance.  4 Guys from Rolla offer a workaround of adding a second textbox and hiding it.

I think Microsoft, if they are aware, need to re-program this functionality in IE to always submit the buttonID – Value pair.  Other browsers work this way so its not impossible.

5. February 2009 13:41 by Duane | Comments (1) | Permalink