How to set connection string in vb.net?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foocc
    New Member
    • Feb 2007
    • 13

    How to set connection string in vb.net?

    Hi, i would like to know how should i set my connection string in vb.net?

    In my VB6 code, this is how i set my connection string:

    conDetail.Conne ctionString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\Docum ents and Settings\FCC\De sktop\vb.net(ne w1)\SapWVA\Data \100\WVAdvert.M DB;Persist Security Info=False;"

    My question here is, how do i do the same thing in vb.net?

    Please help.
    Many thanks.
  • bhar
    Banned
    New Member
    • Apr 2006
    • 37

    #2
    Hi,

    Connecting to a DataSource using SqlClient Connection String in vb 2005

    There are two ways.

    Dim strConnect As String=”Data Source=localhos t;Initial Catalog=pubs;In tegrated Security=SSPI;”
    Dim myConnection As SqlConnection=N ew SqlConnection(s trConnect)
    MyConnection.Op en()

    In the above code, we are taking advantage of the SqlConnection object’s parameterized constructor to set the ConnectionStrin g property directlty, at the same time as it is instantiated.

    Another option is:

    Dim myConnection As SqlConnection=N ew SqlConnection()
    myConnection.Co nnectionString= ”DataSource=loc alhost;Initial Catalog=pubs;In tegrated Security=SSPI;”
    myConnection.Op en()

    Data source – Machine Name
    InitialCatalog – Name of the Database
    Integrated Security – This indicates that the current user’s Windows Credentials are being used to access SQL Server.

    Note: Connection strings require exact syntax, including spacing and case sensitivity in some cases. Visual Studio.Net tools that will help to create connection strings.

    Here is an example of a connection string for a Microsoft Access database.

    Dim myConn As OleDbConnection =New OleDbConnection ()
    myConn.Connecti onString=_
    "Provider=Micro soft.Jet.OLEDB. 4.0;Data " & _
    "Source=C:\data \northwind.mdb; User ID=guest; " &_
    "Password=p5n7U "

    [Link Removed]
    Last edited by Frinavale; Apr 27 '07, 02:37 PM. Reason: Link was removed because it is considered spam

    Comment

    Working...