6 Replies - 1393 Views - Last Post: 30 October 2014 - 09:27 PM Rate Topic: -----

#1 CellulaS   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 19-June 12

Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 06:10 AM

Hello im new to VB.net im trying to connect my sql server 2008 COMException was unhandled?
what did i do wrong ?

Imports System.Data.SqlClient

Module Module1
    Public conn As New ADODB.Connection
    Public rs As New ADODB.Recordset
    Public rss As New ADODB.Recordset
    Public sql As String
    Public userid As String
    Public outpatid As String
    Public usertype As String
    Public Server, Database, User, Password

    Public con As New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=Hospital;User ID=;Password=")
    Public Function opendb()

        If conn.State = 1 Then conn.Close()
        conn.Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=;password=;Initial Catalog=Hospital;Data Source=.\SQLEXPRESS") im getting error in this part its say invalid authorization specification
        Return 0
    End Function
    Public Function CheckNum(ByVal e As KeyEventArgs)
        If (e.KeyCode < 48 Or e.KeyCode > 57) And e.KeyCode <> 8 And (e.KeyCode < 96 Or e.KeyCode > 105) Then
            e.SuppressKeyPress = True
        End If
        Return 0

    End Function
    Function CheckAlpha(ByVal e As KeyEventArgs)
        If e.KeyCode > 48 And e.KeyCode < 57 Then
            e.SuppressKeyPress = True
        End If
        Return 0
    End Function
End Module



Is This A Good Question/Topic? 0
  • +

Replies To: Problem connecting VB.net with sql server 2008

#2 ybadragon   User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 06:20 AM

what is the specific error?
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 06:20 AM

Why do you need two connections, con and conn? If you only need one get rid of the other.

Check your connection string details here:

http://www.connectionstrings.com/
Was This Post Helpful? 2
  • +
  • -

#4 CellulaS   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 19-June 12

Re: Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 07:15 AM

conn.Open("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=;password=;Initial Catalog=Hospital;Data Source=.\SQLEXPRESS") Invalid authorization specification i keep getting problem right here my ms server 2008 .\SQLEXPRESS im only using default. should i download microsoft OLE DB provider for sql server ? could someone help me fix connection for my code

This post has been edited by CellulaS: 30 October 2014 - 07:18 AM

Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 08:25 AM

Are you sure your using the right SQL objects? Why are you using a Function that you don't use the Return value instead of a Sub?
Was This Post Helpful? 1
  • +
  • -

#6 thecoat   User is offline

  • D.I.C Addict

Reputation: 153
  • View blog
  • Posts: 537
  • Joined: 07-December 13

Re: Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 10:27 AM

I believe the default authentication for sql2008express is set to windows security only, if the server isn't configured for SQL authentication you won't be able to connect specifying a user and password.

It also looks like your user and password are blank, which begs the question are you trying to use windows authentication? If so try adding the Integrated Security property and removing the user/password properties.

"provider=sqloledb.1;Data Source=.\SQLExpress;database=Hospital;Integrated Security=SSPI;Persist Security Info=False"


Also this:

View Postandrewsw, on 30 October 2014 - 06:20 AM, said:

Why do you need two connections, con and conn? If you only need one get rid of the other.


Having 2 connections might make sense if you are connecting to different servers, I'm having a hard time trying to think of a scenario where you would need 2 connections using both a .Net provider and an ADO provider. I suspect that the presence of both is more out of confusion and/or troubleshooting than actual need.

This post has been edited by thecoat: 30 October 2014 - 10:27 AM

Was This Post Helpful? 2
  • +
  • -

#7 CellulaS   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 19-June 12

Re: Problem connecting VB.net with sql server 2008

Posted 30 October 2014 - 09:27 PM

thanks alot i got it fix my sql server 2008 was corrupted had to re-install again thanks alot. i was just testing if i could connect to my server and my localhost sorry to be pain

This post has been edited by CellulaS: 30 October 2014 - 09:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1