Results 1 to 6 of 6

Thread: [2005] Connection String

  1. #1

    Thread Starter
    Fanatic Member aNubies's Avatar
    Join Date
    Aug 2008
    Posts
    558

    [2005] Connection String

    How i can make my connectionstring in sql flexible rather than using this:

    Code:
    conn.ConnectionString = "Data Source = ServerName; Initial Catalog = DatabaseName; Integrated Security = True;"
    If I am going to use this what if i place my application in a other computer that connection string will find the path of the server and the database on the previous computer that i work on.

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

    Re: [2005] Connection String

    If you create a Data Source then the IDE offers to put your connection string in the config file by default. Then you only have to edit the config file on each system. Alternatively you can build your connection string using a SqlConnectionStringBuilder, getting the individual properties from wherever you like, e.g. the config file or direct user input.
    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
    Fanatic Member aNubies's Avatar
    Join Date
    Aug 2008
    Posts
    558

    Re: [2005] Connection String

    If you create a Data Source then the IDE offers to put your connection string in the config file by default.
    Are you referring on databinding ?

    Alternatively you can build your connection string using a SqlConnectionStringBuilder, getting the individual properties from wherever you like, e.g. the config file or direct user input.
    How to do that ?

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

    Re: [2005] Connection String

    Quote Originally Posted by aNubies
    How to do that ?

    build your connection string using a SqlConnectionStringBuilder
    and then

    getting the individual properties from wherever you like, e.g. the config file or direct user input.
    You'll have to be more specific if you want more answers.

  5. #5
    New Member
    Join Date
    Aug 2008
    Posts
    1

    Re: [2005] Connection String

    Take a look to SQL ConnectionStringDialog

    It is a dll (with source) for displaying a dialog for connecting, browse the database, create the connectionstring, test it, and save the string to the application settings.

    In my apps I try a connection in the load event. If fails, then I open a SQLConnectionDialog.

    Additionnally, there is a OLEDb connection dialog, so I have modified the class for connecting to access databases.

    Alex

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

    Re: [2005] Connection String

    Quote Originally Posted by aNubies
    Are you referring on databinding ?
    No, I'm referring to creating a Data Source froem either the Data Sources window or the main menu. That will add an entry to your Data Sources window and create a corresponding typed DataSet class. You can then create instances of that class in code, which might then be bound to your controls. Data-binding is not limited to DataSets though.
    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

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