Script to change Port number

  • Hello All,

    Currently the SQL Express edition on my machine is configured to listen on Port 5201, now i would like to change the port to 5301, and need this to be done via a script or a batch file. Is this really possible?

    I have read that it is possible by changing the registry setting on the machine, Is it safe to change the registry settings via a script?

    Below is another query....

    Is it possible to configure the port at the installation time itself, i.e while installing SQL express through cmd prompt it is possible to enable\disable network protocols, but what i want to know is.......is it possible to enable the protocols and then assign a port at the installation itself?

  • I doubt if chaning port is possible with T-SQL.

    Yes, it could be possible to edit the registry settings and do the change but I do not recomend.

    Not sure about your last question.

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • naresh1253 (9/11/2009)


    Hello All,

    Currently the SQL Express edition on my machine is configured to listen on Port 5201, now i would like to change the port to 5301, and need this to be done via a script or a batch file. Is this really possible?

    I have read that it is possible by changing the registry setting on the machine, Is it safe to change the registry settings via a script?

    Below is another query....

    Is it possible to configure the port at the installation time itself, i.e while installing SQL express through cmd prompt it is possible to enable\disable network protocols, but what i want to know is.......is it possible to enable the protocols and then assign a port at the installation itself?

    I would question why you would need to change this via a script or batch, You should have access to change this manually. you can change it via the registry but once again I would question why you cannot do it normally using the sql tools.

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

  • actually my product requires SQL server express as a prerequisite. So i am doing a silent installation of SQL if it does not exist and give any one or the available port number and then notify user about the port number....Instead of giving manual steps to the user on how to configure port and them asking them to perform.

  • naresh1253 (9/11/2009)


    actually my product requires SQL server express as a prerequisite. So i am doing a silent installation of SQL if it does not exist and give any one or the available port number and then notify user about the port number....Instead of giving manual steps to the user on how to configure port and them asking them to perform.

    the port allocation is dynamic, however this link might help you.

    http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/914f8b72-3164-47ae-91fb-f7ed6f8ea7e6

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

  • Thanks for the link mate. That helped me a lot.

  • You can also run setup.exe file with /qn or /qb option while installation.

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • Sure...i'll check these options as well....

  • Not sure how that helps with changing the port number, the switches you mentioned are purely for no ui or basic ui, no prompts. silent install

    --------------------------------------------------------------------------------------
    [highlight]Recommended Articles on How to help us help you and[/highlight]
    [highlight]solve commonly asked questions[/highlight]

    Forum Etiquette: How to post data/code on a forum to get the best help by Jeff Moden[/url]
    Managing Transaction Logs by Gail Shaw[/url]
    How to post Performance problems by Gail Shaw[/url]
    Help, my database is corrupt. Now what? by Gail Shaw[/url]

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply