PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How many app.config files with connection strings do you have?-VBForums
Results 1 to 5 of 5

Thread: How many app.config files with connection strings do you have?

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,046

    How many app.config files with connection strings do you have?

    Is it normal to have an app.config file with a connection string in most of the projects in your solution, or have I gone overboard somehow?
    I am assuming they got generated whenever I added an xsd file to a project.
    The reason I am asking is because I have a request from a co-worker:

    Please add in to your connection string the Application Name property with the appropriate name, i.e. "Application Name=XXX2.0;" This allows me to see who is running what. It may be cool to append the version number too if you're using a constructor to make the string. If you're using a static string stored in app settings then the generic name above is good. Right now I am seeing a bunch of ".net framework" applications in sp_who so it would be good to know which connections belong to 2.0.

    This means I have to go into every app.config file and do this?
    connectionString="Data Source=x;Initial Catalog=x;Integrated Security=True;Application Name=XXX2.0;"
    On *all* the connectionstrings?
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: How many app.config files with connection strings do you have?

    You only need config files for applications, i.e. projects that compile to an EXE. If you have library projects, they will also have a config file but the file itself is never actually used. It exists to show you the config required by your library, which means that any application that references that library needs to include that config in its own config file.

    So, if you have a library project that connects to a database then that project will have a config file that contains a connection string. If you reference that library from an EXE then the config file for that EXE needs to contain that connection string, even if the application itself doesn't connect to the database. When the library code executes, it will look in the config file for the current application to find the connection string.

    What that means for you is that only the application config files actually need the Application Name added to the connection string. It's probably wise to add it to all though, just in case you copy and paste from a library config file to the application config file at some point in the future. That way, you won't lose that attribute value.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,046

    Re: How many app.config files with connection strings do you have?

    OK, thanks.
    You can see my co-worker asked "It may be cool to append the version number too if you're using a constructor to make the string."
    Right now when I run sp_who2, I see XXX2.0. It'd be cool, I agree, if I saw XXX2.0.0.677 and XXX2.0.0.678, etc. so we could differentiate users who were on the newest release versus older ones.

    So I'm thinking...when I made the call into my Settings file to get the connectionstring, that is:
    Code:
            [global::System.Configuration.ApplicationScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
            [global::System.Configuration.DefaultSettingValueAttribute("Data Source=X;Initial Catalog=X;Integrated Security=True;Application Name=" +"XXX2.0")]
            public string myConnectionString
            {
                get
                {
                    return ((string)(this["myConnectionString"]));
                }
            }
    Before returning this["myConnectionString"], I could modify it and instead of returning XXX2.0 as the hardcoded Application Name, I could return XXX + System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion. Is there anything dangerous about that, other than that I am modifying Settings.Designer.cs which is a no-no?
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: How many app.config files with connection strings do you have?

    How are you using the connection string? is it implicitly, e.g. Entity Framework, or explicitly, e.g. creating your own SqlConnection object? If it's the latter then you can just add that value at run time, e.g.
    csharp Code:
    1. var bulder = new SqlConnectionStringBuilder(Properties.Settings.myConnectionString);
    2.  
    3. builder.ApplicationName += System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
    4.  
    5. var connection = new SqlConnection(builder.ConnectionString);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    4,046

    Re: How many app.config files with connection strings do you have?

    Implicitly using DataSets and xsd files.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width