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

G

guy

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)
%>
 
M

Mosley Jones III

guy said:
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
 
A

Aaron Bertrand [MVP]

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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top