Results 1 to 6 of 6

Thread: Reading Sql Connection from .ini file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Reading Sql Connection from .ini file

    Hello can someone help me how to make
    when run project to read information about sql (mssql) connection from the .ini file what database to read,user,password,host

    My.ini
    [Settings]
    Host = 127.0.0.1
    User = sa
    Password = password
    Database = MyDatabase

    and if there is no connection with the settings when run the application to display message, cant connect to database please check configs, else to load the project
    can someone help me how to make it?

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

    Re: Reading Sql Connection from .ini file

    There are plenty of examples around of reading data from an INI file. What do you not understand about them?

    As you read the data, use a SqlConnectionStringBuilder to construct the connection string one component at a time.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Reading Sql Connection from .ini file

    http://www.vbforums.com/showthread.p...Edit-Read-Info
    here is the example that i try to explane

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Reading Sql Connection from .ini file

    is there a reason why you're hell-bent on using an ini file instead of my.settings as i suggested in your other thread about writing to the ini?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    524

    Re: Reading Sql Connection from .ini file

    because i want to change from the .ini file if i use other username password database its much faster instead to enter in code the others

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

    Re: Reading Sql Connection from .ini file

    Quote Originally Posted by diablo21 View Post
    because i want to change from the .ini file if i use other username password database its much faster instead to enter in code the others
    You are misguided. It is certainly easier to have the connection information stored external to the EXE so that you don't need to recompile to change it. The authors of .NET have already thought of that though. You should be storing your connection string in the config file, which is XML and can be read automatically by your application. You should open the Settings page of your project properties and add a setting of type (ConnectionString) there. What you enter will be stored in the application config file automatically and you can retrieve it in code via My.Settings. Easy-peasy.

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