Common Database Connection String ( Powershell)

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Nick Nick 2 years, 6 months ago.

  • Author
    Posts
  • #15465
    Profile photo of Nick
    Nick
    Participant

    Greetings,

    I have requirement to create common connection string to execute all SQL script file or Query and i could not find any example.

    Please could you help me get an example or provide some input based on your experience.

    This will help to achieve my tasks ..!

    using power shell v2.0

    Thanks
    VJ

  • #15466
    Profile photo of Joakim
    Joakim
    Participant

    Hi, is it the actual connection string you need help with or how to conect to the database and get data?

    If you want to have a connectionstring available for all your scripts you can add the connection string to your $PROFILE. That ensures that is is available for your scripts.

    Don Jones have a great example for how you can do this in his code for generating historical reports. The code is available from the OneDrive folder.

  • #15468
    Profile photo of Nick
    Nick
    Participant

    Hi joakim,

    Thank you so much for your quick reply.

    Hers's the steps i would like to connect database :-

    1. Create common script, should have only the connections string info like user/pwd & server & database name with encrypted PWD.

    2. Create .ps1 script to call the connection string and then open connection to execute the QUERY or procedure / .sql file

    3. close the connection sting in the .ps1 file

    4. Done

You must be logged in to reply to this topic.