Results 1 to 15 of 15

Thread: store conn string in ???

  1. #1

    Thread Starter
    Banned
    Join Date
    May 2006
    Posts
    161

    store conn string in ???

    Simple question...
    I need to store a constant kind of like a connection string / or a file path in vb.net. In asp.net I usually store these in the web.config file. Then in aspx when I need the value I simply do:

    ConfigurationSettings.AppSettings("NameOfMyTag")

    to get the value I need. How would I do this in vb.net ? Do I store it in the assemblyinfo file ?

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Re: store conn string in ???

    You have something similar available in vb.Net.

    The xml file named applicationname.Exe.Config will reside where your exe exists and you can use System.Configuration.ConfigurationSettings.AppSettings to read the data within.

  3. #3
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: store conn string in ???

    If you are using 2005, you have the new My namespace. You can add the values to the Settings.settings file and then reference them with My.Settings.ConnectionString, etc.

  4. #4

    Thread Starter
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: store conn string in ???

    I am using vs.net 2003 there is no xml that I see. My exe is inside the bin folder and the only file with it has a .pdb extension.

  5. #5
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Re: store conn string in ???

    Select Add Item and then select "XML File". Make you sure you name the new file "App.Config". The item will be placed in your project directory. But now, when you build the application, Vb.NET will automatically copy the file with the appropriate name to where it's supposed to be (your debug or release directory).

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: store conn string in ???

    Add a config file to your project the same way you add any other file type. Alternatively, if you create a connection in the designer you can open the DynamicProperties section of the properties window and bind the ConnectionString to an entry in the config file there, which will automatically create a config file.

  7. #7

    Thread Starter
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: store conn string in ???

    Quote Originally Posted by Bananafish
    Select Add Item and then select "XML File". Make you sure you name the new file "App.Config". The item will be placed in your project directory. But now, when you build the application, Vb.NET will automatically copy the file with the appropriate name to where it's supposed to be (your debug or release directory).
    Can you give me a sample line item inside of this file...and how to call it.
    Like a constant...

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: store conn string in ???

    In the config file,

    <configuration>
    <appSettings>
    <add key="ConnectionString" value="......." />
    ...

    To access it,

    System.Configuration.ConfigurationSettings.AppSettings ("ConnectionString")

  9. #9
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs down Re: store conn string in ???

    A database connection string stored in plain sight? That's not a security risk.
    ~Peter


  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: store conn string in ???

    Quote Originally Posted by MrGTI
    A database connection string stored in plain sight? That's not a security risk.
    Yeah, it's insecure and the user has direct access to it. One could choose to encrypt the string before placing it in the config file, and decrypt it just before the code needs to use it.

  11. #11

    Thread Starter
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: store conn string in ???

    It would not be insecure in a web app, since the config file sits on the server.

  12. #12

    Thread Starter
    Banned
    Join Date
    May 2006
    Posts
    161

    Re: store conn string in ???

    Quote Originally Posted by MrGTI
    A database connection string stored in plain sight? That's not a security risk.
    Maybe for app.config, Ive never had to write a vb.net with db app...
    but for a web.config asp.net application how is it insecure ?

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: store conn string in ???

    Quote Originally Posted by JAKSupport
    It would not be insecure in a web app, since the config file sits on the server.
    It's more secure than in the case of winforms.

    Unless a hacker gets direct control of the server itself. Otherwise the HttpModules for ASP.NET handle requests for web.config and call it 'unauthorized'.

  14. #14
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Post Re: store conn string in ???

    There are many ways a webserver could be vulnerable.

    Besides the obvious idea of a hacker getting onto the machine, there’s many other ways. Maybe the server is backed up each night, and the backups are stored on another machine. Maybe someone makes a copy of that backup, and then restores it to their personal machine. Then they can browse your files with all the time in the world, and locate your easily visible database connection string.

    Keep that info as tightly guarded as possible!
    ~Peter


  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: store conn string in ???

    .NET 2.0 adds explicit support for config file encryption and on-the-fly decryption. Just one more improvement to add to the list.

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