How to programmatically set connection string to mdf file on install?

Dickie Taylor 1 Reputation point
2021-02-17T23:04:54.52+00:00

I am would like to get the path of the installed mdf file, the user name and computer name and create connection string on install? I have searched and can't seem to find the answer to my question. Seen very similar questions but not trying to do what I am wanting to do. Thank you in advance for any help!

Developer technologies Visual Studio Other
{count} votes

1 answer

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,426 Reputation points
    2021-02-18T07:29:15.417+00:00

    Hi dltaylor,

    I am would like to get the path of the installed mdf file, the user name and computer name and create connection string on install?

    • User name and computer name
      You could use System.Environment Class
    • The path of the installed mdf file
      You could check if the installation information has been written in windows registry, then follow this thread to exact it programmatically.

    Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.