wrote:
> Hi.
>
> I have an app which uses multiple databases and I would like to know
> if there is a way to connect to different databases through OLEdb (or
> any other connection string) which allows me to connect to a different
> database.
>
The Connection object has a property called DefaultDatabase
(
http://msdn.microsoft.com/library/en...ltdatabase.asp)
which allows you to basically switch databases after the connection has been
opened.
> My connection string connects to HelpDesk db.
>
> For example
> .ActiveConnection = xconn
> .CommandType = adCmdStoredProc
> .CommandText = "HR.dbo.proc_Get_Region"
> .Parameters.Refresh
BAD BAD BAD
You are forcing a separate trip to the database to be made in order to
retrieve the parameter metadata. You should use CreateParameter to create
your parameters and append them to the Parameters collection. I wrote a free
tool to generate this code for you - it's available here:
http://www.thrasherwebdesign.com/dow...parameters.zip. The
description is here:
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear
> .Parameters("@iRegionID") = 0
> .Parameters("@iUserID") = userid
> set rsregion = .Execute
>
> Using this syntax, I get the following error.
> Procedure 'proc_Get_Region' expects parameter '@iRegionID', which was
> not supplied.
>
> Stored Procedure syntax is:
> CREATE Procedure proc_Get_Region
> (
> @iRegionID int = 0,
> @iUserID int
> )
Hmm - no output parameters, and you don't seem to need to read the Return
parameter ... you don't need to use an explicit Command object. You can do
this:
xconn.DefaultDatabase = "HR"
set rsregion=createobject("adodb.recordset")
xconn.proc_Get_Region 0, userid, rsregion
if not rsregion.eof then
'process the recordset
else
'handle the empty-recordset situation
end if
Don't forget to close and destroy your recordset and connection objects ...
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"