Sandip's Programming Zen

An attempt to share tech/coding experiences

Solution: ERROR 2003, Can’t connect to MySQL server on ‘localhost’ (10048)

with 8 comments

The behavior is seen on Windows Server 2003.

If your application is using data connections in large numbers than sooner or later it will stop responding after some time and only way to make it working again is resetting iis service.

Asp.Net is using Ephemeral Ports to connect MySql via ODBC but in Windows 2003 server there is no maximum port value defined in registry (surprisingly on Windows XP it is). So after consuming certain number of ports there are no ports available to connect and finally application crashes. I have resolved this issue by creating MaxUserPort value in registry in following way. This has solved my problem.

1. Click Start, click Run, type regedit.exe, and then click OK.

2. Locate and then click the following registry subkey:


3. On the Edit menu, point to New, and then click DWORD Value.

4. Type MaxUserPort and then press ENTER.

5. Double-click the MaxUserPort value, and then type the maximum value in decimal or hexadecimal.

You must type a number in the range of 500065534 (decimal). Setting this parameter to a value outside of the valid range causes the nearest valid value to be used (5000 or 65534).

6. Click OK.

7. Quit Registry Editor.

Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Use this solution on your Own risk.


Written by Sandip

February 19, 2008 at 1:31 pm

Posted in Troubleshooting

8 Responses

Subscribe to comments with RSS.

  1. It worked for us also.. Thanks Sandip


    March 24, 2008 at 9:50 am

  2. I had the same problem and I solved using the component MySQL Connector/NET instead of the usual framework ODBC library.

    You can take a look here for the documentation

    and download source and binaries here


    May 21, 2008 at 2:21 pm

  3. Thanks this helped me a lot.

    Muhammad Hasnain

    September 7, 2008 at 1:49 am

  4. it really helped thanx
    i m using version 5,window xp


    October 23, 2008 at 3:24 pm

  5. You get this error due to the amount of connections you are establishing with the server.

    I had the same message here, and calculating how many trys I was trying, got something about 900*6!

    So.. how I fixed it? You can change your script to do just ONE try of connection, BUT if you did as I did, this is something near the “impossible”.

    Try it.. Change the function to connect with the server to use a persistent one.

    Eg.Using PHP you have the “mysql_connect” and the alternative is “mysql_pconnect”.

    You can find more information about this alternative function here:

    It is simples, when you try to connect, the system looks for a previous “connection”, if it exists, thats the magic, no one is created! But the same old connection is used.

    Bruno Carnaes

    April 15, 2010 at 9:03 pm

  6. Thanks form mysql eror solutions.


    August 22, 2010 at 2:17 am

  7. Very good article ..this is works


    January 11, 2011 at 12:53 pm

  8. great info. this solved my problem. thanks


    March 17, 2011 at 7:38 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: