Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling stored procedure from seperate db

Status
Not open for further replies.

dazzer123

IS-IT--Management
Nov 24, 2003
128
GB
I'm using the following code to call a stored procedure and return it to a recordset.

DIM cnn As New ADODB.Connection
DIM cmdSQL As New ADODB.Command

Set cnn = CurrentProject.Connection
Set cmdSQL.ActiveConnection = cnn
cmdSQL.CommandText = "GetSortBy"
Set rstSortBy = cmdSQL.Execute()

How can I do the same thing but calling a storedprocedure from a different sql db

Thanks in advance for your help
 
Here is an example of setting up a connection string to the pubs database on the sql server bigtuna. This connection can be used just like you used the currentproject connection.

Dim cn As New adodb.Connection
Dim rs As Recordset, connString As String
connString = "provider=SQLOLEDB.1;" & _
"User ID=sa;Initial Catalog=pubs;" & _
"Data Source=bigtuna;" & _
"Persist Security Info=False"
cn.ConnectionString = connString
cn.Open connString
 
Thanks that worked well
Also found another way

Create a stored procedure in current db

Create Procedure ExecStoredProcedure
(
@strQuery VarChar(50)

)

As

EXEC @strQuery

/* set nocount on */
return

And then do

DIM cnn As New ADODB.Connection
DIM cmdSQL As New ADODB.Command

Set cnn = CurrentProject.Connection
Set cmdSQL.ActiveConnection = cnn
cmdSQL.CommandText = "ExecStoredProcedure 'OtherDb.dbo_OtherProcedure'"
Set rstSortBy = cmdSQL.Execute()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top