|
 |
asp_components thread: Problems with a component that connects to a database
Message #1 by "Gabriela" <goyatomari@i...> on Wed, 12 Jul 2000 19:43:48
|
|
Hello, people!
I'm trying to make a component that connects to a database in order to use
it in ASP pages.
The component (it's a dll made with VB 6.0) has a class called DataAccess,
with these methods:
'connects to a database
Public Function Conexion(strConn)
Set Conexion = CreateObject("AdoDb.Connection")
Conexion.Open strConn
End Function
'fills a recordset using the connection established before
Public Function FillRecordset(query, Conn)
Dim rs As Adodb.Recordset
Set rs = New Adodb.Recordset
With rs
.CursorLocation = adUseClient
.ActiveConnection = Conn
.Open query
Set .ActiveConnection = Nothing
End With
Set FillRecordset = rs
End Function
***
In my ASP page, I wrote:
dim miDataAccess,Conn
set miDataAccess = server.CreateObject ("MyComponent.DataAccess")
set Conn = miDataAccess.Conexion (
"Server=wnt_int;database=HotelesYaDesa;driver={SQL Server};UID=sa;Pwd=;")
***
The connection is established without errors.
When I use the FillREcordset method, I can display the records without any
problem, using the variable Conn created this way.
But when I try to use this same variable Conn with a recordset created in
the ASP page (not with this FillRecordset method), I can't do it!!!
If, after the lines above, I write in the ASP page:
dim Rs
set rs=server.createobject("adodb.recordset")
Rs.Open "select * from clientes" , Conn
the browser displays the following message:
"ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another. "
Why? If I can use it with the FillREcordset method, why can't I use it this
way?
Anyone out there knows what's going on here? I need your help...
Thank you very much!
GAby
Message #2 by fredrik.normen@s... on Fri, 14 Jul 2000 13:37:12
|
|
First of all try to user Conexion in you Fillfunction instead to call it on
the ASP page. And make shore you close the connection before you leave the
function. This will increase Performance and Scalability.
But if you would have it like your way,
then you have to make som changes.
This is your function:
Public Function Conexion(strConn)
Set Conexion = CreateObject("AdoDb.Connection")
Conexion.Open strConn
End Function
This is your function with some changes.
Public Function Conexion(strConn) As ADODB.Connection
Dim con as ADODB.Connection
Set con = New AdoDb.Connection
con.Open strConn
set Conextion = con
End Function
/Fredrik Normén
Message #3 by "GABRIELA OYATOMARI" <Goyatomari@i...> on Fri, 14 Jul 2000 14:27:34 -0300
|
|
Thanks a lot, Fredrik, for your answer!
I think you're right about this, could it be that "passing" connections
between ASP and components is the real problem here?
And that this opening, using and closing connections have to take place in
the same environment? (ASP or Component).
Anyway thanks a lot for your help!
Gaby
>>> <fredrik 07/14 1:37 PM >>>
First of all try to user Conexion in you Fillfunction instead to call it
on
the ASP page. And make shore you close the connection before you leave
the
function. This will increase Performance and Scalability.
But if you would have it like your way,
then you have to make som changes.
This is your function:
Public Function Conexion(strConn)
Set Conexion =3D CreateObject("AdoDb.Connection")
Conexion.Open strConn
End Function
This is your function with some changes.
Public Function Conexion(strConn) As ADODB.Connection
Dim con as ADODB.Connection
Set con =3D New AdoDb.Connection
con.Open strConn
set Conextion =3D con
End Function
/Fredrik NormTn
Message #4 by fredrik.normen@s... on Sun, 16 Jul 2000 11:57:56
|
|
you are welcome !
I don't think the problem is to pass the connection object between ASP and
components. But is not a good way to do it because of performance problem.
Have in mind to use ASP to display data and the object to give the page
information to display. And close every Database connection as soon as
possible.
/Fredrik Normen
Message #5 by "José Luis Gallego" <jlgallego@s...> on Tue, 18 Jul 2000 11:5:10
|
|
Hi Gabriela,
Perhaps this is a silly hint but it's recommended using "ByVal" at every
function parameter and it's highly recommended returning a type from a
function call.
Un saludo.
José.
|
|
 |