Typed DataSets and App.Config...A Cautionary Tale


I am working on a project where I have separated the Typed DataSets into a separate Assembly.  I nievely made the Typed DataSets use a named Connection String in this assembly.  So when I attached to the Database when creating my DataSets, I saw that it was using a Connection String called "MyConnection".

In this assembly, the designer created an app.config and a Settings.setting object.  All sounded good.  So in my ASP.NET 2.0 project, I setup the connection string in the web.config and called it "MyConnection".  This all worked until I deployed it to a server, when all hell broke loose.  After deployment, my code that did *not* use Typed DataSets (mostly DataSources) worked fine with my new "MyConnection" connection string...but...

Everywhere I used the Typed DataSets it was failing to connect to the database.  When I looked at it it seems that the Typed DataSets were using the connection string I used on my dev box...but no app.config to be seen.  How was it getting that bad connection string?  Well it seems that the connection string information is being embedded as the "default" connection string to use if it can't find the connection string in the configuration.  Ok, this is bad...I'd hate for my assembly to actually have stuff like my password embedded in it, but I doubt that happens.  I was using integrated security so I haven't tested the password embedding yet.

But what is strange is the connection string was in the web.config.  What gives?  Well the Typed DataSet satellite assembly named my connection string with namespace and setting prefixes.  "MyConnection" became "MyApp.Properties.Settings.MyConnection" because the serialization of the name includes all of that.  Yeech...

For now I added that as a connection string to my web.config and got over my initial issue, but I am still digging to find a better solution.  I'll let you know what I find.



Shawn
Shawn Wildermuth
Author, Teacher, and Coach




My Courses

Wilder Minds Training
Vue.js by Example (New Lower Price)
Bootstrap 4 by Example (New Lower Price)
Intro to Font Awesome 5 (Free Course)
Pluralsight
Building an API with ASP.NET Core (New Course)
Building a Web App with ASP.NET Core, MVC6, EF Core, Bootstrap and Angular (updated for 2.2)
Less: Getting Started (New)
Using Visual Studio Code for ASP.NET Core Projects
Implementing ASP.NET Web API

Application Name WilderBlog Environment Name Production
Application Ver v4.0.30319 Runtime Framework x86
App Path D:\home\site\wwwroot\ Runtime Version .NET Core 4.6.27617.04
Operating System Microsoft Windows 10.0.14393 Runtime Arch X86