Connecting to SQLServer in VB6 (using ADODB) works fine within VB appliction but not from ASP page

Discussion in 'ASP General' started by guy, Feb 23, 2004.

  1. guy

    guy Guest

    Hello All,
    I'm have a VB function that connect to SQL SERVER , get's information
    and returns the relavant string.
    using this function within VB application (say cmdbutton) works great,
    but when trying to activate the function from asp page, i'm getting
    nothing.
    can anyone help here ?

    here is the VB CODE :
    =============================================================================
    Option Explicit

    Private Conn As ADODB.Connection
    Private rs As ADODB.Recordset

    Private Function connectDB() As Boolean
    Dim ConnectionString As String
    ConnectionString = "Provider=SQLOLEDB.1;" _
    & "Integrated Security=SSPI;" _
    & "Persist Security Info=False;" _
    & "Initial Catalog=DBName;" _
    & "Data Source=SERVER"
    On Error GoTo errhandler
    Set Conn = New ADODB.Connection
    Conn.ConnectionTimeout = 5
    Conn.ConnectionString = ConnectionString

    Conn.Open

    If Conn.State = adStateOpen Then
    connectDB = True
    Else
    connectDB = False
    End If
    Exit Function
    errhandler:
    MsgBox "The Following Error accured:" & vbCrLf & _
    Err.Description & vbCrLf & _
    "Error Number:" & _
    Err.Number, vbMsgBoxRight + vbMsgBoxRtlReading + vbCritical
    End Function

    Private Sub closeDB()
    On Error GoTo errhandler
    Conn.Close
    Exit Sub
    errhandler:
    MsgBox "The Following Error accured:" & vbCrLf & _
    Err.Description & vbCrLf & _
    "Error Number:" & _
    Err.Number, vbMsgBoxRight + vbMsgBoxRtlReading + vbCritical
    End Sub

    Public Function getSomthing(id As String) As String
    Dim getID As String
    If connectDB Then
    Set rs = Conn.Execute("SELECT PName FROM PTable"
    & "WHERE PID LIKE '" & id & "'")
    Do While Not rs.EOF
    getID = rs.Fields("PName")
    rs.MoveNext
    Loop
    closeDB
    Else
    getID = "ooops ... connection to the server didn't succedded"
    End If
    getSonsOf = getID
    End Function

    ==============================================================================


    calling the function getSomthing from VB code returns the right
    result,
    but when compiling the code to .dll - the call to the function fails
    !!

    here is the ASP Code :
    <%
    set obj = Server.CreateObject("DBManagerProject.DBManager")
    Response.Write obj.getSonsOf (100)
    %>
    guy, Feb 23, 2004
    #1
    1. Advertising

  2. "guy" <> wrote in message
    news:...
    > Hello All,
    > I'm have a VB function that connect to SQL SERVER , get's information
    > and returns the relavant string.
    > using this function within VB application (say cmdbutton) works great,
    > but when trying to activate the function from asp page, i'm getting
    > nothing.
    > can anyone help here ?
    >
    > here is the VB CODE :
    >

    ============================================================================
    =


    set Conn = Server.CreateObject(ADODB.Connection)
    set rs = Server.CreateObject(ADODB.Recordset)



    Function connectDB

    Dim ConnectionString


    ConnectionString = "Provider=SQLOLEDB.1;" _
    & "Integrated Security=SSPI;" _
    & "Persist Security Info=False;" _
    & "Initial Catalog=DBName;" _
    & "Data Source=SERVER"


    Conn.ConnectionTimeout = 5
    Conn.ConnectionString = ConnectionString

    Conn.Open ConnectionString

    If Conn.State = 1 Then
    connectDB = True
    Else
    connectDB = False
    End If
    Exit Function


















    errhandler:
    MsgBox "The Following Error accured:" & vbCrLf & _
    Err.Description & vbCrLf & _
    "Error Number:" & _
    Err.Number, vbMsgBoxRight + vbMsgBoxRtlReading + vbCritical
    End Function

    > Private Sub closeDB()
    > On Error GoTo errhandler
    > Conn.Close
    > Exit Sub
    > errhandler:
    > MsgBox "The Following Error accured:" & vbCrLf & _
    > Err.Description & vbCrLf & _
    > "Error Number:" & _
    > Err.Number, vbMsgBoxRight + vbMsgBoxRtlReading + vbCritical
    > End Sub
    >
    > Public Function getSomthing(id As String) As String
    > Dim getID As String
    > If connectDB Then
    > Set rs = Conn.Execute("SELECT PName FROM PTable"
    > & "WHERE PID LIKE '" & id & "'")
    > Do While Not rs.EOF
    > getID = rs.Fields("PName")
    > rs.MoveNext
    > Loop
    > closeDB
    > Else
    > getID = "ooops ... connection to the server didn't succedded"
    > End If
    > getSonsOf = getID
    > End Function
    >
    >

    ============================================================================
    ==
    >
    >
    > calling the function getSomthing from VB code returns the right
    > result,
    > but when compiling the code to .dll - the call to the function fails
    > !!
    >
    > here is the ASP Code :
    > <%
    > set obj = Server.CreateObject("DBManagerProject.DBManager")
    > Response.Write obj.getSonsOf (100)
    > %>
    Mosley Jones III, Feb 23, 2004
    #2
    1. Advertising

  3. This is because you are launching VB as *you* and you are authenticating
    against SQL Server as *you.*

    The ASP page is authenticating as IUSR_your_machine_name which very likely
    isn't recognized by SQL Server. I suggest using SQL authentication unless
    you are planning on disabling anonymous access, having all of your users
    authenticate, and adding them to a group that has sufficient access to SQL
    Server...

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "guy" <> wrote in message
    news:...
    > Hello All,
    > I'm have a VB function that connect to SQL SERVER , get's information
    > and returns the relavant string.
    > using this function within VB application (say cmdbutton) works great,
    > but when trying to activate the function from asp page, i'm getting
    > nothing.
    > can anyone help here ?
    >
    > here is the VB CODE :
    >

    ============================================================================
    =
    > Option Explicit
    >
    > Private Conn As ADODB.Connection
    > Private rs As ADODB.Recordset
    >
    > Private Function connectDB() As Boolean
    > Dim ConnectionString As String
    > ConnectionString = "Provider=SQLOLEDB.1;" _
    > & "Integrated Security=SSPI;" _
    > & "Persist Security Info=False;" _
    > & "Initial Catalog=DBName;" _
    > & "Data Source=SERVER"
    > On Error GoTo errhandler
    > Set Conn = New ADODB.Connection
    > Conn.ConnectionTimeout = 5
    > Conn.ConnectionString = ConnectionString
    >
    > Conn.Open
    >
    > If Conn.State = adStateOpen Then
    > connectDB = True
    > Else
    > connectDB = False
    > End If
    > Exit Function
    > errhandler:
    > MsgBox "The Following Error accured:" & vbCrLf & _
    > Err.Description & vbCrLf & _
    > "Error Number:" & _
    > Err.Number, vbMsgBoxRight + vbMsgBoxRtlReading + vbCritical
    > End Function
    >
    > Private Sub closeDB()
    > On Error GoTo errhandler
    > Conn.Close
    > Exit Sub
    > errhandler:
    > MsgBox "The Following Error accured:" & vbCrLf & _
    > Err.Description & vbCrLf & _
    > "Error Number:" & _
    > Err.Number, vbMsgBoxRight + vbMsgBoxRtlReading + vbCritical
    > End Sub
    >
    > Public Function getSomthing(id As String) As String
    > Dim getID As String
    > If connectDB Then
    > Set rs = Conn.Execute("SELECT PName FROM PTable"
    > & "WHERE PID LIKE '" & id & "'")
    > Do While Not rs.EOF
    > getID = rs.Fields("PName")
    > rs.MoveNext
    > Loop
    > closeDB
    > Else
    > getID = "ooops ... connection to the server didn't succedded"
    > End If
    > getSonsOf = getID
    > End Function
    >
    >

    ============================================================================
    ==
    >
    >
    > calling the function getSomthing from VB code returns the right
    > result,
    > but when compiling the code to .dll - the call to the function fails
    > !!
    >
    > here is the ASP Code :
    > <%
    > set obj = Server.CreateObject("DBManagerProject.DBManager")
    > Response.Write obj.getSonsOf (100)
    > %>
    Aaron Bertrand [MVP], Feb 23, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. luis valencia

    Dts works from SqlServer but not from ASP.net

    luis valencia, Apr 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,460
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Apr 19, 2005
  2. Eric
    Replies:
    5
    Views:
    567
  3. =?Utf-8?B?SmVmZnJleQ==?=

    Upgrading ASP w/SQLserver 2000 to ASP.NET w/ SQLserver 2005

    =?Utf-8?B?SmVmZnJleQ==?=, Apr 6, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    477
    sloan
    Apr 27, 2007
  4. Mufasa
    Replies:
    2
    Views:
    339
    Michael Nemtsev
    Apr 19, 2007
  5. Bina Desai
    Replies:
    1
    Views:
    153
    Ray at
    Oct 10, 2003
Loading...

Share This Page