5 Replies - 65172 Views - Last Post: 06 November 2011 - 10:52 PM Rate Topic: -----

#1 KnooKie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-May 10

Connecting to SQL Server 2008 Exp from VB 2010 Exp

Posted 07 May 2010 - 09:44 PM

Using Win7 Home Prem 32-bit
SQL Server 2008 Express
Visual Basic 2010 Express
.NET 4 Framework

I am trying connect to a SQL Server database i have created using Visual Basic. Both reside on my local machine (PAUL-PC).

Here is what i have done so far but i am missing something (or more worryingly i have got it completely wrong)...

Public Class frmMainMDI

    Dim con As New OleDb.OleDbConnection
    Dim rs As New OleDb.OleDbDataAdapter
    Dim cmd As New OleDb.OleDbCommand
    Dim strconnect As String

    Private Sub frmMainMDI_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        strconnect = "Provider=SQLOLEDB;Data Source=PAUL-PC\\SQLExpress;Initial Catalog=ScubaDiveBookingSystem; Integrated Security=SSPI;"
        con.Open(strconnect)     'definitely not sure about this bit


    End Sub

End Class



So i have an MDI form and i want to make a connection to SQL Server when that form loads.

I do not want to use a DSN if possible so am trying to use Oledb. Not sure also of the DataAdaptor declaration as in previous versions i used many years ago it was recordset.

I have been looking at these sites to try and help but am not sure...
http://www.carlproth...derForSQLServer
http://www.sqlteam.c...nnection-string

I would like to use a trusted connection to connect.

Any pointers would be very helpful

This post has been edited by KnooKie: 07 May 2010 - 10:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Connecting to SQL Server 2008 Exp from VB 2010 Exp

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Connecting to SQL Server 2008 Exp from VB 2010 Exp

Posted 07 May 2010 - 09:45 PM

This is the VB6 forum. Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#3 KnooKie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-May 10

Re: Connecting to SQL Server 2008 Exp from VB 2010 Exp

Posted 07 May 2010 - 09:57 PM

View PostPsychoCoder, on 07 May 2010 - 08:45 PM, said:

This is the VB6 forum. Moved to VB.NET :)



Ok thanks - i just picked Visual Basic off the forum combo box
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Connecting to SQL Server 2008 Exp from VB 2010 Exp

Posted 07 May 2010 - 10:10 PM

Read this tutorial: SQL Basics in VB.NET

I think it will help with what you're looking to do
Was This Post Helpful? 0
  • +
  • -

#5 KnooKie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-May 10

Re: Connecting to SQL Server 2008 Exp from VB 2010 Exp

Posted 08 May 2010 - 12:59 AM

View PostPsychoCoder, on 07 May 2010 - 09:10 PM, said:

Read this tutorial: SQL Basics in VB.NET

I think it will help with what you're looking to do



Thank you - I'll take a good look at that. I can see things have changed some since my early programming days
Was This Post Helpful? 0
  • +
  • -

#6 yasodhamohan  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 06-November 11

Re: Connecting to SQL Server 2008 Exp from VB 2010 Exp

Posted 06 November 2011 - 10:52 PM

try this,

Dim DBConn As OleDb.OleDbConnection

DBConn = New OleDb.OleDbConnection("Provider=SQLOLEDB;Data Source=user_name;Database=work_order;Uid=sa; Pwd=password;")

DBConn .open()
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1