Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Required Help to Connect to MS-Sql Server thru VB Coding

yadlapatiyadlapati Member Posts: 22
hi every body !

I Require sample code to Connect to MS-Sql Server thru VB Coding.
Any of u help me !

Comments

  • GideonOmegaGideonOmega Member Posts: 617
    : hi every body !
    :
    : I Require sample code to Connect to MS-Sql Server thru VB Coding.
    : Any of u help me !
    :
    now I think by far the easiest way to set up your connection is to create a dsn through odbc to your database(make sure to use sql authentication) then once the dsn is created, connectivity becomes very easy, for instance if the dsn that you created was called "MultiLease" and you used sql authentication the code below would open your connection object named "g_objConn" and connect it to whatever database you specify in your dsn:
    [code]
    Set g_objConn = New ADODB.Connection
    g_objConn.Open "DSN=MultiLease;User ID=;Password=;"
    [/code]

    if you are not sure how to create the dsn to the sql server just put up a reply as I have a user guide to create the dsn for a project that I completed using sql server that would give you the idea. Or if you need to use a connection string instead same as above.


    [blue]
    C:Dos
    C:Dos Run
    Run Dos Run
    [/blue]

  • Daniel_JohnsDaniel_Johns Member Posts: 18
    : : hi every body !
    : :
    : : I Require sample code to Connect to MS-Sql Server thru VB Coding.
    : : Any of u help me !
    : :
    : now I think by far the easiest way to set up your connection is to create a dsn through odbc to your database(make sure to use sql authentication) then once the dsn is created, connectivity becomes very easy, for instance if the dsn that you created was called "MultiLease" and you used sql authentication the code below would open your connection object named "g_objConn" and connect it to whatever database you specify in your dsn:
    : [code]
    : Set g_objConn = New ADODB.Connection
    : g_objConn.Open "DSN=MultiLease;User ID=;Password=;"
    : [/code]
    :
    : if you are not sure how to create the dsn to the sql server just put up a reply as I have a user guide to create the dsn for a project that I completed using sql server that would give you the idea. Or if you need to use a connection string instead same as above.
    :
    :
    : [blue]
    : C:Dos
    : C:Dos Run
    : Run Dos Run
    : [/blue]
    :
    :

    if you want to have a DSN-less connection to your SQL server...here's how...(just the string, and i provide you different strings for different database driver -for your reference-)

    'Different databases DSN Less Connection String

    'For SQL Server Driver
    BuildSQLCon = "driver={SQL Server};database=databaseNAme;server=ServerName;uid=UserName;pwd=Password

    'For Oracle Driver
    BuildSQLCon = "Provider=MSDAORA;Data Source=DatabaseName;User ID=scott; Password=tiger;"

    'For mySQL Driver
    BuildSQLCon = "driver={MySQL ODBC 3.51 Driver};server=ServerName;uid=root;pwd=root;database=databaseName;option=NUM"

    'For MS-Access Driver
    BuildSQLCon = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & app.path & "/databaseName.MDB"

    <<--U gona w8 hir FATBOY -- w8 hir 2morow! -->>

Sign In or Register to comment.