none
global connection from vb to sql server RRS feed

  • Question

  • Hi everybody

    I'm new to ado and just want to know how to define a connection from vb to sql server, that can be reached

    from any form or any class in the vb application??


    SqlDream

    Tuesday, January 8, 2013 6:49 PM

Answers

  • That completely depends how you create it. I assume you are talking about VB.Net.

    In that you can create a connection to a database with

    dim connection as new DBConnection("The ConnectionString") 'DB stends for the DataBase provider used.

    But be aware if you use the designer way it is instead of that in the Config.sys

    Where you put it is your own responsibility if you would it Public then do that for instance by

    Private connection as new DBConnection("the ConnectionString") 'DB stends for the DataBase provider used.

    For those finding this and using C# 

    private DBConnection Connection = new DBConnection("the ConnectionString"); //DB stends for the DataBase provider used.


    Success
    Cor

    • Marked as answer by Alexander Sun Wednesday, January 30, 2013 7:46 AM
    Thursday, January 10, 2013 1:43 PM
  • May I also suggest reading some of my blog posts about DataAccess ... check out my 3-part series on Data Access for some basic ideas. The code is in C#, but you should be able to understand the concepts.

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post gets into using anonymous delegates and may be too much for a beginner.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    • Proposed as answer by Alexander Sun Wednesday, January 30, 2013 7:45 AM
    • Marked as answer by Alexander Sun Wednesday, January 30, 2013 7:46 AM
    Thursday, January 10, 2013 3:11 PM

All replies

  • If you are using a singleton connection object (there is no global in VB.net), you are defeating the purpose of ADO.Net and SQL Server's connection pools. Generally database connections are created on the fly (often in background threads to keep the UI responsive) and closed as soon as possible.

    If you use an ADO typed dataset or better, use ADO.Net Entity Framework, ADO.Net will open can close the connection for you by default.



    Visual C++ MVP

    Tuesday, January 8, 2013 7:39 PM
  • That completely depends how you create it. I assume you are talking about VB.Net.

    In that you can create a connection to a database with

    dim connection as new DBConnection("The ConnectionString") 'DB stends for the DataBase provider used.

    But be aware if you use the designer way it is instead of that in the Config.sys

    Where you put it is your own responsibility if you would it Public then do that for instance by

    Private connection as new DBConnection("the ConnectionString") 'DB stends for the DataBase provider used.

    For those finding this and using C# 

    private DBConnection Connection = new DBConnection("the ConnectionString"); //DB stends for the DataBase provider used.


    Success
    Cor

    • Marked as answer by Alexander Sun Wednesday, January 30, 2013 7:46 AM
    Thursday, January 10, 2013 1:43 PM
  • May I also suggest reading some of my blog posts about DataAccess ... check out my 3-part series on Data Access for some basic ideas. The code is in C#, but you should be able to understand the concepts.

    http://geek-goddess-bonnie.blogspot.com/2009/09/dataaccess-part-i.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-ii.html
    http://geek-goddess-bonnie.blogspot.com/2009/10/dataaccess-part-iii.html

    Each post adds extra complexity to the Data Access classes, but more flexiblity. The first post is enough to get you going in the right direction and give you a general idea of the concept, but the second post is more useful. The third post gets into using anonymous delegates and may be too much for a beginner.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    • Proposed as answer by Alexander Sun Wednesday, January 30, 2013 7:45 AM
    • Marked as answer by Alexander Sun Wednesday, January 30, 2013 7:46 AM
    Thursday, January 10, 2013 3:11 PM