Results 1 to 3 of 3

Thread: [Resolved] Compiled Connection String Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2017
    Posts
    7

    Resolved [Resolved] Compiled Connection String Problem

    I have a 3 Tier asp.net application. I have the dataset and table adapters separated into different projects. The WCF service that uses the table adapters is also in a separate project. The problem that I now have is that the connection string is being compiled into the DLL for the table adapter. When I deploy the web service, the connection string is compile with the table adapter DLL and placed in the WCF service's BIN folder. I opened up the DLL and confirmed that it is in the DLL since I could not find it anywhere else. I need it to be in an config file so that I can change it for different environments and so that I can encrypt it.

    How do I configure the project to use a connection string either in the WCF service's web.config or some separate config file?
    Last edited by Traveller; Apr 26th, 2018 at 10:56 AM.

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Compiled Connection String Problem

    I think you should be able to add a reference to System.Configuration and System.Configuration.ConfigurationManager to the DLL and then just access the web.config the same way you would from the web app.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2017
    Posts
    7

    Re: Compiled Connection String Problem

    Quote Originally Posted by PlausiblyDamp View Post
    I think you should be able to add a reference to System.Configuration and System.Configuration.ConfigurationManager to the DLL and then just access the web.config the same way you would from the web app.

    Thanks for the suggestion. I added the reference but the solution still compiled the same with the connection string embedded in the DLL.


    I eventually found the solution. First I had to use an external connection string. Then I had to move the connection string file to my WCF service project that uses the table adapters. Finally, I added the connection string file back to the table adapters project by using Add >> Existing Item >> Add As Link. Now when I publish the WCF service, the external connection string file is published to the service's base folder. I can't find the connection string in the table adapter DLL anymore and the service does not work if I remove the connection string file. That confirms that it is using the external connection string file.

    I ran into some problems and had to add a few additional steps. This involves modifying the dataset designer file and project settings which means you will have to repeat these step every time you make a modification to the dataset. Make a backup of your dataset project before doing this.

    In addition to the file setup that I outlined above, do the following:

    In the <dataset>.designer.vb
    add: Imports System.Configuration
    find Sub 'InitConnection()'. Replace 'Global.LAISDAL.My.MySettings.Default.<your connection>' with 'ConfigurationManager.ConnectionStrings("<your connection>").ConnectionString'
    Do a find and replace all for the above strings.

    Right-Click on your dataset project >> Properties >> Settings Delete all connection strings


    Note: The automatically generated connection string name in your app.config will be in the following format <project name>.My.MySettings.<connection string name> I would recommend shortening removing everything except the <connection string name>. You are no longer storing it in the project so it no longer makes sense to have it follow that naming format. It may prevent confusion for future developers that look at your code. Speaking of which, I would also recommend putting a text file in the project explaining how you modified the designer file and the project settings.
    Last edited by Traveller; Apr 30th, 2018 at 11:49 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width