Results 1 to 8 of 8

Thread: [02/03] Connection String Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    [02/03] Connection String Help

    HI. I just want to ask if anyone can provide me an example of connection string.
    Im using VS 2003 and i want to connect to MS SQL.. Thanks

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

    Re: [02/03] Connection String Help

    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
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: [02/03] Connection String Help

    Thanks for the source... it has many choices but i still need the proper coding... Im Using VS 2003 and connecting to MS SQL.
    Code:
            Dim connection As New SqlClient.SqlConnection("connection string")
            Dim command As New SqlClient.SqlCommand("SELECT * from    test_ezon", connection)
       
    
            connection.Open()
    
    
            Dim reader As SqlClient.SqlDataReader = command.ExecuteReader()
    
    
    
            While reader.Read()
    
                MessageBox.Show(String.Format("There are {0} {1} remaining in stock.", _
                                              reader("Quantity"), _
                                              reader("Name")))
    
            End While
    
            reader.Close()
            connection.Close()

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

    Re: [02/03] Connection String Help

    You asked for the appropriate connection string format for SQL Server and that site provides it. The question you asked has been answered. What exactly is the problem? Are you asking, without actually asking, for more than just a connection string?
    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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: [02/03] Connection String Help

    Actually I'm having this problems..

    Code:
    Dim dBase As String
            dBase = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=TSI-CWISTIAN;"
    
            Dim connection As New SqlClient.SqlConnection(dBase)
            Dim command As New SqlClient.SqlCommand("SELECT * from test_ezon", connection)
    having this codes... im having this error msg...

    Code:
    An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll
    
    Additional information: Keyword not supported: 'provider

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

    Re: [02/03] Connection String Help

    If you don't follow the right links then you're not going to get the right information. You're using a SqlConnection to connect to SQL Server and you're using an OLEDB connection string for SQL Server Compact Edition. Let's read that page I linked to. It provides links to connection strings for SQL Server 2008, SQL Server 2005, SQL Server 2000/7.0. I'm not sure why you arbitrarily decided to follow the CE link when you're not using CE. Follow the right link and then take a connection string from the right section.
    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: [02/03] Connection String Help

    Im not really famillar with the choices.. i use the

    SqlConnection (.NET)
    Standard Security

    Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

    Code:
    Dim dBase As String
            dBase = "Data Source=TSI-CWISTIAN;Initial Catalog=test_ezon;Integrated Security=SSPI;"
    
            Dim connection As New SqlClient.SqlConnection(dBase)
            Dim command As New SqlClient.SqlCommand("SELECT * from test_ezon", connection)
       
    
            connection.Open()
    
    
            Dim reader As SqlClient.SqlDataReader = command.ExecuteReader()
    
    
    
    
            While reader.Read()
    
                MessageBox.Show(String.Format("There are {0} {1} remaining in stock.", _
                                              reader("Quantity"), _
                                              reader("Name")))
    
            End While
    
            reader.Close()
            connection.Close()
    now my problem is if im using the right code... kinldly pls check my codes./..
    i having problem with this line

    Dim reader As SqlClient.SqlDataReader = command.ExecuteReader()
    i just use the one you posted at databank...

    Code:
       1.
          Dim connection As New SqlConnection("connection string here")
       2.
          Dim command As New SqlCommand("SELECT Quantity, Unit, Name FROM StockItem", connection)
       3.
           
       4.
          connection.Open()
       5.
           
       6.
          Dim reader As SqlDataReader = command.ExecuteReader()
       7.
           
       8.
          While reader.Read()
       9.
              MessageBox.Show(String.Format("There are {0} {1} of {2} remaining in stock.", _
      10.
                                            reader("Quantity"), _
      11.
                                            reader("Unit"), _
      12.
                                            reader("Name")))
      13.
          End While
      14.
           
      15.
          reader.Close()
      16.
          connection.Close()

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

    Re: [02/03] Connection String Help

    That's my CodeBank thread and I provided the very same link to ConnectionStrings.com in that thread. Beginner or not, you should be able to read what the different databases are that they provide examples for and follow the appropriate link, then read through that page and make an attempt at deciding which is the appropriate one.

    Now, you're on the right page and you're in the right section so that's good. That connections string means you're logging onto an unnamed instance of SQL Server as the current Windows user on a machine named TSI-CWISTIAN and opening a database named test_ezon. Is that what you want to do? If so then it's correct. Did it work when you tried it? If so then that would also suggest that it's correct. If it didn't work then maybe it's not correct.
    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