Re: Returning a closed recordset...
- From: "William \(Bill\) Vaughn" <billvaNoSpam@xxxxxxxxx>
- Date: Fri, 23 Sep 2005 10:46:34 -0700
Try
SELECT * FROM MyDatabase..MyTable WHERE...
You can also set the Initial Catalog on the Connection to switch databases
or in ADO.NET change it in code and let ADO.NET handle it.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Griff" <Howling@xxxxxxxx> wrote in message
news:%23hBEg7FwFHA.2664@xxxxxxxxxxxxxxxxxxxxxxx
>I have created a connection object to my sqlserver using the following
>connection string:
>
> "Provider=SQLOLEDB;Password=*******;Persist Security Info=True;User
> ID=**;Data Source=" & sServerName & ;Initial Catalog=" & sDatabase
>
> This SQLServer has many databases on it, all with identical schema.
>
> I create some SQL that I wish to use against all the databases in turn:
>
> sSQL = "USE " & db & " SELECT * from mytable where ...."
>
> db is a variable that names the specific database that I wish to query.
>
> If I trap this SQL and throw it in QueryAnalyzer (pointing to the wrong
> database) then it correctly brings back the data from the right database
> (i.e. it understands the "use db " prefix)
>
> However, when I run this in my code, it simply returns a recordset whose
> state is closed (= 0). If I "corrupt" the SQL, it will happily tell me
> that an object (such as a table name) does not exist.
>
> The VB code (actually, it's VBScript since it's within a classic ASP page)
> that I use to get the recordset is at the end of this post, and for the
> rest of the program this happily returns open recordsets (with the same
> connection object)
>
> So....any ideas why a recordset whose state = 0 is being returned?
>
> Thanks
>
> Griff
>
> --------------
>
> private function getRecordset(byVal oCN, byVal sSQL)
> Dim oRS
>
> set oRS = CreateObject("ADODB.Recordset")
> with oRs
> .CursorLocation = adUseClient
> .LockType = adLockBatchOptimistic
> .CursorType = adOpenStatic
> .ActiveConnection = oCN
>
> .Source = sSQL
>
> .Open
>
> .ActiveConnection = Nothing
> end with
>
> set getRecordset = oRS
> end function
>
>
.
- References:
- Returning a closed recordset...
- From: Griff
- Returning a closed recordset...
- Prev by Date: Re: Returning a closed recordset...
- Next by Date: Comparing two recordsets
- Previous by thread: Re: Returning a closed recordset...
- Next by thread: Comparing two recordsets
- Index(es):
Relevant Pages
|