Connecting to sql server

I am wanting to write a visual basic front end to my sql server 2000 database. I have downloaded visual basic express 2005 and it only seems to want to connect to an sql server express database.

Is it possible to connect visual basic express to sql server 2000 and if not whats the best way to go about this



Answer this question

Connecting to sql server

  • Dean Wagner

    You should be able to access the database through code.  I am running vs 2005 not the vb express so I can not test this.  Try droping a datagridview on the form.  Add this code to the forms load event

    <code>

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim da As SqlDataAdapter
            Dim conn As SqlConnection
            Dim ds As New DataSet
            Dim strConn As String


            strConn = String.Format("Server = {0};", Environment.MachineName)
            strConn &= "Database = NorthWind; Integrated Security = SSPI;"
            conn = New SqlConnection(strConn)
            da = New SqlDataAdapter("Select * from Products", conn)
            da.Fill(ds, "Products")

            DataGridView1.DataSource = ds.Tables("Products")

        End Sub

    </code>



  • Eduardo Cobuci

     

    Yes in a way... but remeber that only the Wizards and automatic processes for development will not connect to remote sources. You can connect to other databases by coding the solution manually. One method that I have talked about a bit in the forums is to connect your code to bindable objects then the wizards can connect to the binable objects, the Personal Web Site Starter Kit has a good example of this that can be ported to a windows forms solution.



  • is4me2

     

    One thing you will have to remember is that the Express edition database wizards will only connect to the local machine and SQL Express, to connect to remote sources you will need to code the data layare yourself. One way is to write the data layer to produce objects that can be bound to, then the wizards to pick them up.



  • peterdarvas

     codeman43 wrote:
    Try this site for connection strings, http://www.connectionstrings.com/

    That's a pretty good resource. Thanks for posting.



  • Scheinka

    The sqlConnection object only seems to connect to the SQLServer2005. I've used the OleDBConnection to connect to SQL Server 2000:

    Dim conn as System.Data.OleDb.OleDbConnection

    make sure you specify the provider (provider=sqloledb) for SQL Server.

    Hope that helps.

    SJW

     



  • Yvan

    My preferred source for connection strings:

    http://www.carlprothman.net/Default.aspx tabid=81

    Just about every possible database you can think of... with good code examples too.

    Oh... and it covers ADO.Net and ADO Classic connection strings too.  :)



  • THal

    Try this site for connection strings, http://www.connectionstrings.com/

  • Rich S

    Is this a case of a 'free' program will only work in a limited capacity and the full version does connect to an outside source
  • Connecting to sql server