Showing posts with label command. Show all posts
Showing posts with label command. Show all posts

Sunday, March 25, 2012

ASP sp execution returning closed recordset

Can anybody tell me why a) when running a stored proc from an asp page to
return a recordset the command succeeds if the sp queries an existing table
directly, but b) if the stored proc populates results into a different
table, temporary table, global temp table, or table variable, then queries
one of these, the asp page reports that the recordset object is closed. If
using a table, I have set grant, select, update, delete permissions for the
asp page user account, so it doesn't appear to be a permissioning issue. If
run in Query Analyser the sp runs fine of course.

Abridged asp code is as follows:
StoredProc = Request.querystring("SP")
oConn.ConnectionString = "Provider=SQLOLEDB etc"
oConn.Open
set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = oConn
oCmd.CommandText = StoredProc
oCmd.CommandType = adCmdStoredProc
oCmd.Parameters.Refresh
'code here that populates the parameters of the oCmd object correctly
Set oRs = Server.CreateObject("ADODB.Recordset")
With oRS
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
'execute the SP returning the result into a recordset
.Open oCmd
End With
' Save data into IIS response object
Response.ContentType = "text/xml"
oRs.Save Response, adPersistXML
'the line above fails with stored procs from example B below, reporting "not
allowed when object is closed", but works with example A

SP Example A - this one works fine
Create Proc spTestA AS
SELECT ID FROM FileList
GO

SP Example B - this one doesn't work from ASP but runs fine in QA
Create Proc spTestB AS
DECLARE @.Results Table (ID TinyInt)
INSERT INTO @.Results SELECT ID FROM FileList
SELECT ID FROM @.Results
GO

I can see the SP executing using profiler when the asp page is called for
both sp's above, so it doesn't appear to be a problem with the execution.
It's something to do with returning the result set from the table variable.

Thanks,

Robin Hammond"Robin Hammond" wrote:

<snip
> SP Example B - this one doesn't work from ASP but runs fine in QA
> Create Proc spTestB AS
> DECLARE @.Results Table (ID TinyInt)
> INSERT INTO @.Results SELECT ID FROM FileList
> SELECT ID FROM @.Results
> GO

<snip
Robin,

The problem is that you're getting back a closed recordset with "records
affected" info from SQL Server: using the NextRecordset method in ADO will
get the actual recordset you're looking for. A good rule of thumb is to
watch the output from a stored proc in QA: anytime you see a resultset or a
message about records affected, then you know this could pop up.

A more efficient solution (and the one I prefer) if you don't need any data
back but the result of the SELECT is to use SET NOCOUNT...

Create Proc spTestB AS
SET NOCOUNT ON
DECLARE @.Results Table (ID TinyInt)
INSERT INTO @.Results SELECT ID FROM FileList

SET NOCOUNT OFF
SELECT ID FROM @.Results
GO

Craigsql

Tuesday, March 20, 2012

ASP 2.0 sql syntax change?

I was simply trying to create a sql command using ASP 2.0 but the syntax appears to have changed. I was trying to write the following:

SqlCommand

cmdUpdateData =newSqlCommand("AddMessage", myConnection);

cmdUpdateData.CommandType = CommandType.StoredProcedure;

But, intellisence will not offer me the second 'CommandType' on the second line?? It works fine using ASP 1.1 but not here on 2.0

Can anyone please help?

Looks ok to me. Are you importing system.data and system.data.sqlclient?|||

Yes I was lacking the system.data namespace!

Many thanks,

James

|||

That all works fine now, but a little further down my code where I fill the datagrid I have another problem with the changing sysntax.

In visual studio 2003 I would use the following:

try

{

//first open the connection

myConnection.Open();

//fill data set with data from sql data adapter

myAdapter.Fill(ds);

//bind the data grid to the datasetthis.dgdShowStudents.DataSource=ds;this.dgdShowStudents.DataKeyField="StudentId";this.dgdShowStudents.DataBind();

However, using ASP2.0 intellisence does not pick up on DataKeyField. Should I be using something else? or do I have to use the wizard for filling a grid. I'd rather do it with code?

|||Is it a datagrid or a gridview?|||GridView. I assumed it would take the same code as the DataGrid|||

If you are using the gridview, I would normally bind it to a sqldatasource control instead of using code. It's a lot simplier and it handles some things very nicely for you (Sortable columns, caching, etc).

The gridview is similiar, but not the same as a datagrid. As for the datakeys, the gridview supports multiple column binding, which I don't believe the datagrid did. I believe the property you are looking for is called DataKeyNames for the gridview.

|||

Many thanks for the help,

James

Monday, March 19, 2012

ASCMD executing multiple MDX commands in one batch file

Has anyone got an example of ASCMD executing multiple MDX commands in one batch file? Or are we restricted to one MDX command only? We haven't been able to use multiple commands.

The doc at http://msdn2.microsoft.com/en-us/library/ms186692.aspx states that you can have multiple xmla commands.

<Command> <Batch Transaction="Boolean" ProcessAffectedObjects="Boolean"> <Bindings>...</Bindings> <DataSource>...</DataSource> <DataSourceView>...</DataSourceView> <ErrorConfiguration>...</ErrorConfiguration> <Parallel>...</Parallel> <!-- One or more XMLA commands --> </Batch> </Command>

I think ascmd is already sending through the <Command> element, so you only need to pass it the elements under that. If you put the following into a text file and pass it into ascmd, it will execute 2 create commands, creating two empty databases called Test Database 1 and Test Database 2.

<Batch Transaction="false" ProcessAffectedObjects="false" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Create>
<ObjectDefinition>
<Database xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Test Database 1</Name>
<Description>A test database.</Description>
</Database>
</ObjectDefinition>
</Create>
<Create>
<ObjectDefinition>
<Database xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Test Database 2</Name>
<Description>A test database.</Description>
</Database>
</ObjectDefinition>
</Create>
</Batch>

|||

You cannot have multiple MDX commands in your batch. Batch is intended for execution of several processing commands not MDX.

I believe next version of ASCMD will support GO statement. So you'd be able to create an input file with several MDX statements separated by the GO. Very much the same way it is done in SQL.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Sorry contexbi, Edward is correct BOL is inaccurate. I read "MDX Command", but I was thinking "XMLA Command" when I first answered your question.

As you may know MDX statements are sent in a "Statement" element and you cannot have more than 1 of these in an XMLA command/batch. Other commands (like my create example) can be batched up, but until BOL is fixed you can't really tell which ones until you try. I believe that the restriction on only allowing a single MDX statement is a security feature to prevent potential "MDX injection" attacks.

Management Studio does implement the "GO" statement to execute multiple MDX statements, but this is because it breaks up and sends the MDX separately but I don't think you can get SSMS to run unattended.

Your only approach at the moment would be to call ascmd multiple times from a batch file.

|||

Thanks for the update and clarification. The documentation was confusing.

Any ETA for the next version of ASCMD that supports multiple MDX statements in a batch? SP2?

|||

Hello,
Can we process the partitions and dimensions in one xmla file?
The reason I ask is that we will use the parallel tag to process the dimensions in parallel. But how do I ensure that the partition/ measure group is processed after the dimensions in a single XMLA script?

Rgds
HariK

|||

You can definitely have dimensions and partitions in a single batch command.

Analysis Server will analyzes every object involved in processing and builds a processing schedule the way dimensions are processed first.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

ASCMD executing multiple MDX commands in one batch file

Has anyone got an example of ASCMD executing multiple MDX commands in one batch file? Or are we restricted to one MDX command only? We haven't been able to use multiple commands.

The doc at http://msdn2.microsoft.com/en-us/library/ms186692.aspx states that you can have multiple xmla commands.

<Command> <Batch Transaction="Boolean" ProcessAffectedObjects="Boolean"> <Bindings>...</Bindings> <DataSource>...</DataSource> <DataSourceView>...</DataSourceView> <ErrorConfiguration>...</ErrorConfiguration> <Parallel>...</Parallel> <!-- One or more XMLA commands --> </Batch> </Command>

I think ascmd is already sending through the <Command> element, so you only need to pass it the elements under that. If you put the following into a text file and pass it into ascmd, it will execute 2 create commands, creating two empty databases called Test Database 1 and Test Database 2.

<Batch Transaction="false" ProcessAffectedObjects="false" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<Create>
<ObjectDefinition>
<Database xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Test Database 1</Name>
<Description>A test database.</Description>
</Database>
</ObjectDefinition>
</Create>
<Create>
<ObjectDefinition>
<Database xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Test Database 2</Name>
<Description>A test database.</Description>
</Database>
</ObjectDefinition>
</Create>
</Batch>

|||

You cannot have multiple MDX commands in your batch. Batch is intended for execution of several processing commands not MDX.

I believe next version of ASCMD will support GO statement. So you'd be able to create an input file with several MDX statements separated by the GO. Very much the same way it is done in SQL.

Edward Melomed.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

Sorry contexbi, Edward is correct BOL is inaccurate. I read "MDX Command", but I was thinking "XMLA Command" when I first answered your question.

As you may know MDX statements are sent in a "Statement" element and you cannot have more than 1 of these in an XMLA command/batch. Other commands (like my create example) can be batched up, but until BOL is fixed you can't really tell which ones until you try. I believe that the restriction on only allowing a single MDX statement is a security feature to prevent potential "MDX injection" attacks.

Management Studio does implement the "GO" statement to execute multiple MDX statements, but this is because it breaks up and sends the MDX separately but I don't think you can get SSMS to run unattended.

Your only approach at the moment would be to call ascmd multiple times from a batch file.

|||

Thanks for the update and clarification. The documentation was confusing.

Any ETA for the next version of ASCMD that supports multiple MDX statements in a batch? SP2?

|||

Hello,
Can we process the partitions and dimensions in one xmla file?
The reason I ask is that we will use the parallel tag to process the dimensions in parallel. But how do I ensure that the partition/ measure group is processed after the dimensions in a single XMLA script?

Rgds
HariK

|||

You can definitely have dimensions and partitions in a single batch command.

Analysis Server will analyzes every object involved in processing and builds a processing schedule the way dimensions are processed first.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.