.NET Notes

  • SQLMetal is located in C:\Program Files\Microsoft SDKs\Windows\vn.nn\bin
  • Here’s the easiest way I’ve come across to use TableAdapters in a class library, but allow applications that use that library to change the connection string (both programmatically and as part of the config file).
    1. Make the TableAdapter’s connection string a setting in your library. (In your class library, this should actually resolve to a database server, otherwise, you’re not going to be able to create/edit TableAdapters effectively. But it should be a development server, because this will be your library’s default setting.)
    2. To modify this setting in the web.config or app.config file, you just have to use the full setting name as the connection string name. This should be something to the effect of MyClassesNamespace.Properties.Settings.MyConnectionString.
    3. That same property, however, is not accessible if you want to set the connection string programmatically. Instead, you should probably set up a function like this:

      public static void SetDatabaseConnectionString(string connString
      {
          Assembly asm = Assembly.GetCallingAssembly();
          Configuration config = ConfigurationManager.OpenExeConfiguration(asm.Location);
          config.ConnectionStrings.ConnectionStrings["MyClassesNamespace.Properties.Settings.MyConnectionString"].ConnectionString = connString;
          config.Save();
      }

    You can also make the Connection property of TableAdapters publicly available using this method. This is cleaner than the previous solution, but can be more of a hassle since you would have to change each instance of a TableAdapter.