Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Connecting to SQLServer in VB6 (using ADODB) works fine within VB appliction but not from ASP page

Reply
Thread Tools

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

 
 
guy
Guest
Posts: n/a
 
      02-23-2004
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)
%>
 
Reply With Quote
 
 
 
 
Mosley Jones III
Guest
Posts: n/a
 
      02-23-2004

"guy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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)
> %>



 
Reply With Quote
 
 
 
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      02-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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)
> %>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Upgrading ASP w/SQLserver 2000 to ASP.NET w/ SQLserver 2005 =?Utf-8?B?SmVmZnJleQ==?= ASP .Net 2 04-27-2007 03:33 PM
Web Services on a Windows 2000 IIS 5.x ASP.Net 1.1 works fine but not on 2003 Mufasa ASP .Net 2 04-19-2007 08:09 PM
Session State works for InProc, but not for SQLServer mode Jamie Schatte ASP .Net 1 07-21-2006 09:29 PM
Page works fine with internal webserver but not on IIS Eric ASP .Net 5 12-05-2005 08:20 PM
Dts works from SqlServer but not from ASP.net luis valencia ASP .Net 1 04-19-2005 02:02 PM



Advertisments