Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, March 29, 2012

error: Cursor not returned from query

I'm a really beginner about sql2000.
During my test I have created the following query. It's works ok until I
do't add the code included in section A, when I add it the i obtain the
error: Cursor not returned from query

Anyone can help me?

Thanks Carlo M.

set nocount on

IF OBJECT_ID('storico_big') IS NULL -- section A begin
create table storico_big( data datetime,
bcarrier varchar(20),
bda CHAR(30),
bzone char(50),
bdur int) ;
insert into storico_big -- section A
end

select top 10000
adetdate,bcarrier,bda,bzone,bdur
from pp_cdr (nolock)
where
adetdate < :data_fin and adetdate > :data_in order by adetdate
set nocount off

-- end of queryIW2FIV (carlo.merlini[NONROMPERE]@.libero.it) writes:
> I'm a really beginner about sql2000.
> During my test I have created the following query. It's works ok until I
> do't add the code included in section A, when I add it the i obtain the
> error: Cursor not returned from query

Apparently you are using some environment unknown to me. At least I
don't recognize the message.

> IF OBJECT_ID('storico_big') IS NULL -- section A begin
> create table storico_big( data datetime,
> bcarrier varchar(20),
> bda CHAR(30),
> bzone char(50),
> bdur int) ;
> insert into storico_big -- section A
> end

Since there are several apparent syntax errors here, it would have been nice
if you environment had returned the errors from SQL Server, rather than
bitching about the missing cursor.

It can be a good to run the query from Query Analyzer to get better
error diagnostics.

I don't really want to suggest a correction, because I can't understand
what you are trying to do. It appears that in the same batch that you first
want to create a table, insert into it, and then select data from another
table.

Possibly you want to insert the data from the SELECT statement into
storico_big, but in such case you should

1) get rid of that extraneous end
2) add an explicit column list to the INSERT statement.

However, I have a feeling that if you insert data into the table, the
client environment will still complain about a missing cursor...

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:
> IW2FIV (carlo.merlini[NONROMPERE]@.libero.it) writes:
> > I'm a really beginner about sql2000.
> > During my test I have created the following query. It's works ok until I
> > do't add the code included in section A, when I add it the i obtain the
> > error: Cursor not returned from query
> Apparently you are using some environment unknown to me. At least I
> don't recognize the message.
I would suspect that it's some data layer (such as ADO, ADO.NET, DAO,
etc), which has at least two different methods of performing work in
the database - one for performing data retrieval and another (possibly
on another object, if the layer is object oriented) which allows data
manipulation.

For instance, ADO.NET has ExecuteReader and ExecuteNonQuery methods on
it's command object.

Damien|||Damien (Damien_The_Unbeliever@.hotmail.com) writes:
> I would suspect that it's some data layer (such as ADO, ADO.NET, DAO,
> etc), which has at least two different methods of performing work in
> the database - one for performing data retrieval and another (possibly
> on another object, if the layer is object oriented) which allows data
> manipulation.
> For instance, ADO.NET has ExecuteReader and ExecuteNonQuery methods on
> it's command object.

Obviously IWZFIV is not using ADO .Net. ADO .Net does work with cursors
at all, as far as a I know. A more substantial clue is the condition:

adetdate < :data_fin and adetdate > :data_in order by adetdate

Apparently IWZFIV is using some form of embedded SQL.

Anyway, I would not really describe ADO .Net as providing different methods
for different purposes. If all you want is minimalism, you can do every-
thing with ExecuteReader. The other methods, ExecuteNonQuery, ExecuteScalar
and DataAdapter.Fill can be seen as convenience methods implemented on
top of ExecuteReader. (OK, this is not really true. There are some
fine differences when there are multiple error messages and result sets
interleaved.)
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Tuesday, March 27, 2012

error: connection is busy

Error: 0xC0202009 at Load SQL Deals, Insert SQL Deals [12494]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Connection is busy with results for another command".

Why isn't the connection manager managing this?

How can I trace the cause? The data flow component (insert SQL deals) is just a simple INSERT statment.You can always run SQL Profiler to see what's going on.

Error: Command not properly ended

Hi there,
Would appreciate if someone can have a glance at this code, and tell me
what SQL Talk doesnt like about it?
SELECT X, Y, Z, A, B FROM TSECURITY_LEVEL INTO :x, :y, :z, :a, :b
WHERE 1=1 ORDER BY A;
^
Error: Command not properly ended
Thanks All,
SamSam
SELECT <columns list> INTO #Test FROM MyTable WHERE blabalabala
"Sam" <sammA11111@.hotmail.com> wrote in message
news:1132738877.588734.57500@.g49g2000cwa.googlegroups.com...
> Hi there,
> Would appreciate if someone can have a glance at this code, and tell me
> what SQL Talk doesnt like about it?
> SELECT X, Y, Z, A, B FROM TSECURITY_LEVEL INTO :x, :y, :z, :a, :b
> WHERE 1=1 ORDER BY A;
> ^
> Error: Command not properly ended
> Thanks All,
> Sam
>|||Thanks for the reply Uri.
rookie mistake, and the problem is sorted ;)
sam

Error: Command not properly ended

Hi there,
Would appreciate if someone can have a glance at this code, and tell me
what SQL Talk doesnt like about it?
SELECT X, Y, Z, A, B FROM TSECURITY_LEVEL INTO :x, :y, :z, :a, :b
WHERE 1=1 ORDER BY A;
^
Error: Command not properly ended
Thanks All,
SamSam
SELECT <columns list> INTO #Test FROM MyTable WHERE blabalabala
"Sam" <sammA11111@.hotmail.com> wrote in message
news:1132738877.588734.57500@.g49g2000cwa.googlegroups.com...
> Hi there,
> Would appreciate if someone can have a glance at this code, and tell me
> what SQL Talk doesnt like about it?
> SELECT X, Y, Z, A, B FROM TSECURITY_LEVEL INTO :x, :y, :z, :a, :b
> WHERE 1=1 ORDER BY A;
> ^
> Error: Command not properly ended
> Thanks All,
> Sam
>|||Thanks for the reply Uri.
rookie mistake, and the problem is sorted ;)
samsql

Error: Command not properly ended

Hi there,
Would appreciate if someone can have a glance at this code, and tell me
what SQL Talk doesnt like about it?
SELECT X, Y, Z, A, B FROM TSECURITY_LEVEL INTO :x, :y, :z, :a, :b
WHERE 1=1 ORDER BY A;
^
Error: Command not properly ended
Thanks All,
Sam
Sam
SELECT <columns list> INTO #Test FROM MyTable WHERE blabalabala
"Sam" <sammA11111@.hotmail.com> wrote in message
news:1132738877.588734.57500@.g49g2000cwa.googlegro ups.com...
> Hi there,
> Would appreciate if someone can have a glance at this code, and tell me
> what SQL Talk doesnt like about it?
> SELECT X, Y, Z, A, B FROM TSECURITY_LEVEL INTO :x, :y, :z, :a, :b
> WHERE 1=1 ORDER BY A;
> ^
> Error: Command not properly ended
> Thanks All,
> Sam
>
|||Thanks for the reply Uri.
rookie mistake, and the problem is sorted ;)
sam

Monday, March 19, 2012

Error: 17806, Severity: 20, State: 2

We installed SQL Server 2005 Std Ed and MSProject application uses the instance..

Getting following Eorr Message


SSPI handshake failed with error code 0x80090311 while establishing a connection with integrated security; the connection has been closed. [CLIENT: <named pipe>]

Appreciate your help to fix this

Thanks

Arul

This is an SSIS forum. Try here for Project - http://www.microsoft.com/office/community/en-us/default.mspx

|||Hi,

1.) Mention the servername in FQDN format or use ip address. This may be due to Named pipes
2.) Try changing the protocols, its better to use TCP/IP port. Try connect using servername,portnumber

Sunday, March 11, 2012

Error: 'SubQuery Returned More than 1 Value'

I have some code that calls a stored procedure on SQL Server 2005 using the Microsoft JDBC driver 1.1. The code normally works however, every once in a while an exception is thrown:

Code Snippet

com.microsoft.sqlserver.jdbc.SQLServerException: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !, <,<=, >, >=, or when the subquery is used as an expression.

Generally, this has been resolved by restarting SQL Server 2005, but why is it showing up to being with?

Stored Procedure:

Code Snippet

ALTER Procedure [dbo].[addRecord]
@.userID int,
@.itemID int,
@.info varchar(50),
@.comment varchar(50),
@.output int output
AS

Declare @.dateSubmitted datetime
set @.dateSubmitted = getDate();

--Insert the new record. THIS TABLE has an ID identity Primary Key
--column that auto-increments.
insert into RecordTable
(UserPerson, Information, DateSubmitted)
values (@.userID, @.info, @.dateSubmitted);

Get the ID Assigned in the record table. The Item table
has a Foreign key on this column.
Declare @.assignedID int
set @.assignedID = (select ID from RecordTable where DateSubmitted = @.dateSubmitted)

/**Set the output parameter.*/
set @.output = @.assignedID;

--Now update the Item Table.
insert into Item
(ID, RecordID, Comment)
values (@.item,@.assignedID, @.comment);

set @.assignedID = (select ID from RecordTable where DateSubmitted = @.dateSubmitted)

my guess is that you get that error because you insert more than one record with the same datesubmitted value.

|||

CharlieXXX wrote:

set @.assignedID = (select ID from RecordTable where DateSubmitted = @.dateSubmitted)

my guess is that you get that error because you insert more than one record with the same datesubmitted value.

That's not possible. The error occurs even when the RecordTable is empty.
|||

SomeDeveloperPerson wrote:

CharlieXXX wrote:

set @.assignedID = (select ID from RecordTable where DateSubmitted = @.dateSubmitted)

my guess is that you get that error because you insert more than one record with the same datesubmitted value.

That's not possible. The error occurs even when the RecordTable is empty.

Charlie... you're actually correct. I modified the line to:

Code Snippet

set @.assignedID = (select MAX(ID) from RecordTable where DateSubmitted = @.dateSubmitted)

And it works with no problems now. Apparently the code is executing faster than expected so that several records are being written in under a millisecond.
|||

You can reduce the 'effort' of the procedure with this simple alteration:

Instead of having another query to obtain the IDENTITY value of the just entered row, use the SCOPE_IDENTITY() function.

Code Snippet


--Insert the new record. THIS TABLE has an ID identity Primary Key
--column that auto-increments.
insert into RecordTable
(UserPerson, Information, DateSubmitted)
values (@.userID, @.info, @.dateSubmitted);

Declare @.assignedID int
set @.assignedID = SCOPE_IDENTITY()

It saves a small amount of unnecessary server 'work' since the SCOPE_IDENTITY() is part of the return information from the original insert.

And using MAX() in the fashion that you are could potentially have you obtaining the value from a row inserted by another user. Not a very reliable prospect.

Friday, March 9, 2012

Error. My aspx file cant access server to connect to database

Hi,

I am writing my first aspx file to connect to a standalone SQL Server which is separated from the IIS webserver. The code is

<HTML>
<HEAD>
<TITLE>Store Locator</TITLE>
<script runat="server">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
if Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection("Provider=sqloledb;" _
& "server=dailyplanet;" _
& "Initial Catalog=JAVSTORE;" _
& "User Id=javtrader;" _
& "Password=rage123;")
DBCommand = New OleDbDataAdapter _
("Select * " _
& "From JAVInventory " _
& "Where ID > ((Select COUNT(ID) " _
& "From JAVInventory ) - 100)" _
& "Order By ID DESC", DBConn)
DBCommand.Fill(DSPageData, _
"RecentJAVs")
' ddlZipCode.DataSource = _
' DSPageData.Tables("RecentJAVs").DefaultView
' ddlZipCode.DataBind()
End If
End Sub

I used Visual .Net and Web Matrix and was able to connect to the sql server with the Data Connection to view the tables. However, when I use IIS or the Visual .Net debugger to run the aspx file, it get the following error.. please help..

Server Error in '/javtrade' Application.
------------------------

[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

Source Error:

Line 21: & "From JAVInventory ) - 100)" _
Line 22: & "Order By ID DESC", DBConn)
Line 23: DBCommand.Fill(DSPageData, _
Line 24: "RecentJAVs")
Line 25: ' ddlZipCode.DataSource = _

Source File: c:\inetpub\wwwroot\javtrade\management.aspx Line: 23

Stack Trace:

[OleDbException (0x80004005): [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
System.Data.OleDb.OleDbConnection.InitializeProvider()
System.Data.OleDb.OleDbConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +44
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
ASP.management_aspx.Page_Load(Object Sender, EventArgs E) in c:\inetpub\wwwroot\javtrade\management.aspx:23
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731FYI, when using sql server it is better to use the sql namespace over the oledb. I assume you have a connection string in your web.config file. This can be formed in two ways, one using a trusted connection, or the other being uid=; and pwd=; the login and password for sql respectively. Either version of the connection string must include the server name, which is localhost, 127.0.0.1 if on the localmachine or the actual name or ip of the server.

Wednesday, March 7, 2012

Error with stored procedure

I have the following code in my code behind page:

Dim CN = New SqlConnection(ConfigurationSettings.AppSettings("connectionstring"))
Dim CM As New SqlCommand("spCCF_CrossTab", CN)
CM.CommandType = CommandType.StoredProcedure
CM.Parameters.Add(New SqlParameter("@.LocationID", "CCFIF"))
CM.Parameters.Add(New SqlParameter("@.BeginDate", dtbStart.Text))
CM.Parameters.Add(New SqlParameter("@.EndDate", dtbEnd.Text))
CN.Open()
DR = CM.ExecuteReader(CommandBehavior.CloseConnection)
dgReport.DataSource = DR
dgReport.DataBind()

A SQL exception is thrown: Incorrect syntax near the keyword 'END'

But I turned on tracing in Enterprise Manager, the following request is sent to SQL:

exec spCCF_CrossTab @.LocationID = N'CCFIF', @.BeginDate = N'11/3/2003', @.EndDate = N'11/4/2003'

In query analyzer the above line executes without error and returns the expected information.

My stored procedure is:


CREATE PROCEDURE spCCF_CrossTab
@.LocationID varchar(10),
@.BeginDate varchar(10),
@.EndDate varchar(10)
AS

declare @.select varchar(8000), @.sumfunc varchar(100), @.pivot varchar(100), @.table varchar(100), @.where varchar(1000)

select @.select='SELECT dbo.ActionCodes.Name AS Action FROM dbo.Productivity_CCF LEFT OUTER JOIN dbo.ActionCodes ON dbo.Productivity_CCF.ActionID = dbo.ActionCodes.ID LEFT OUTER JOIN dbo.UserInfo ON dbo.Productivity_CCF.UserID = dbo.UserInfo.ID WHERE (dbo.Productivity_CCF.[Date] BETWEEN CONVERT(DATETIME, ''' + @.BeginDate + ''', 101) AND CONVERT(DATETIME, ''' + @.EndDate + ''', 101)) GROUP BY dbo.UserInfo.UserName, dbo.ActionCodes.Name order by Action'
select @.sumfunc= 'COUNT(ActionID)'
select @.pivot='UserName'
select @.table= 'UserInfo'
select @.where='(dbo.UserInfo.LocationID = ''' + @.LocationID + ''' and dbo.UserInfo.Inactive<>1 )'

DECLARE @.sql varchar(8000), @.delim varchar(1)
SET NOCOUNT ON
SET ANSI_WARNINGS OFF

EXEC ('SELECT ' + @.pivot + ' AS pivot INTO ##pivot FROM ' + @.table + ' WHERE 1=2')
EXEC ('INSERT INTO ##pivot SELECT DISTINCT ' + @.pivot + ' FROM ' + @.table + ' WHERE '
+ @.pivot + ' Is Not Null and ' + @.where)

SELECT @.sql='', @.sumfunc=stuff(@.sumfunc, len(@.sumfunc), 1, ' END)' )

SELECT @.delim=(CASE Sign( CharIndex('char', data_type)+CharIndex('date', data_type) )
WHEN 0 THEN '' ELSE '''' END)
FROM tempdb.information_schema.columns
WHERE table_name='##pivot' AND column_name='pivot'

SELECT @.sql=@.sql + '''' + convert(varchar(100), pivot) + ''' = ' +
stuff(@.sumfunc,charindex( '(', @.sumfunc )+1, 0, ' CASE ' + @.pivot + ' WHEN '
+ @.delim + convert(varchar(100), pivot) + @.delim + ' THEN ' ) + ', ' FROM ##pivot

DROP TABLE ##pivot

SELECT @.sql=left(@.sql, len(@.sql)-1)
SELECT @.select=stuff(@.select, charindex(' FROM ', @.select)+1, 0, ', ' + @.sql + ' ')

EXEC (@.select)
SET ANSI_WARNINGS ON
GO

I've been banging my head on this for quite some time now, any insight someone might have as to the problem would be greatly appreciated! Thanks!I don't see the ELSE and END part of the CASE statement in the code below.


SELECT @.sql=@.sql + '''' + convert(varchar(100), pivot) + ''' = ' +
stuff(@.sumfunc,charindex( '(', @.sumfunc )+1, 0, ' CASE ' + @.pivot + ' WHEN '
+ @.delim + convert(varchar(100), pivot) + @.delim + ' THEN ' ) + ', 'should be something more here? FROM ##pivot

But that doesn't explain why it works in Query Analyzer but not through code.|||I'm using the code from this article: http://www.sqlteam.com/item.asp?ItemID=2955
which I have seen recommended before on the forums so I'm assuming someone has gotten this to work.

I've added a few things but have left everything after the statement below unchanged.
<code>
SELECT @.sql='', @.sumfunc=stuff(@.sumfunc, len(@.sumfunc), 1, 'END)')
<code
Again, it does work successfully in query analyzer and SQL trace does not appear to be generating any errors.|||The code in the article runs fine for me against the Pub database. Yes, many people have gotten it to work.

But you are not running the exact code from the article, so that's a moot point.

My suggestion would be to specify the datatype of your parameters explicitly in your ASP.NET code. It looks like ASP.NET is assuming nVarchar. I don't know if that makes a difference, but I would try that. Additionally, I would add an Output parameter to the stored procedure and pass back the @.select variable to your ASP.NET page and have your ASP.NET page display it. This will show you exactly what the stored procedure is trying to execute and might help your debugging effort.

Terri|||The stored procedure runs fine for me when in Query Analzyer. The problems is when I'm trying to call it from the ASP page.

I removed my modifications from the SP and am still running into the same exact error on the aspx page. I am already explicity setting the datatype for the parameters. Setting an output parameter in the SP is doing nothing in my debug efforts since it never gets to that point in the code and is erroring prior.

The error my aspx page is throwing a SQL exception: Incorrect syntax near the keyword 'END'.

I'm still trudging away at this and am not getting any closer to solving the problem. Any other insight on this problem?
Thanks!|||We need to see what @.select holds when your stored procedure goes to EXEC it.

There are a few ways to do this. Can you add an OUTPUT parameter to your stored procedure to hold @.select, and then output the value of this parameter on your page and then let us know what it is?

Terri|||Can you tell me how to get the output parameter to return to the aspx page as I'm getting an error when trying to do so? i have the following:


...
arParms(3) = New SqlParameter("select", SqlDbType.NVarChar, 8000)
arParms(3).Direction = ParameterDirection.ReturnValue
...
Dim strReturn As String = arParms(3).ToString ' also tried response.write (arParms(3).Value)
Response.Write(strReturn)

SP: DECLARE @.sql varchar(8000)
and instead of exec @.select I have return @.select


Error I get: Syntax error converting the varchar value 'SELECT dbo.ActionCodes.Name AS Action , 'asmith ' = COUNT(ActionID), 'ashelts' = COUNT ... (and then too long of a select statement to write out the entire message).

In debugging I did notice that this line of code in the sp:


SELECT @.sql='', @.sumfunc=stuff(@.sumfunc, len(@.sumfunc), 1, 'END)' )

was causing part of the problem because the select statement looked like:
SELECT dbo.ActionCodes.Name AS Action , 'asmith ' = COUNT(ActionID END)

So I removed the END, now I'm getting a new error but I can't get to completely write on the screen I get as SQL exception: The name 'SELECT dbo.ActionCodes... (part of the select statement). I've tried simplifying my query and it still is too long to display the entire error.

Thanks

On a frustrating side; What I still can't understand it WHY does the stored procedure work (with the parameters I have from the aspx page) in Query Analyzer?|||Ok - actually got the entire sql error finally:

The name 'SELECT dbo.ActionCodes.Name AS Action , 'asmith ' = COUNT(ActionID) FROM dbo.Productivity_CCF LEFT OUTER JOIN dbo.ActionCodes ON dbo.Productivity_CCF.ActionID = dbo.ActionCodes.ID LEFT OUTER JOIN dbo.UserInfo ON dbo.Productivity_CCF.UserID = dbo.UserInfo.ID GROUP BY dbo.UserInfo.UserName, dbo.ActionCodes.Name' is not a valid identifier.|||To get the value of @.select back to your ASP.NET page, I think you should have:


arParms(3) = New SqlParameter("@.select", SqlDbType.NVarChar, 8000)
arParms(3).Direction = ParameterDirection.Output

You shouldn't need to RETURN @.select in the stored procedure. Just comment out the EXEC @.select line so no errors are generated.

But I am afraid I am leading you astray. If your stored procedure was running correctly from query analyzer with the desired parameters, then your stored procedure should not need any revisions.

Is this still returning the correct results from Query Analyzer?

exec spCCF_CrossTab @.LocationID = N'CCFIF', @.BeginDate = N'11/3/2003', @.EndDate = N'11/4/2003'

If so, can you temporarily forego the Command parameters and just put that exec statement into your ASP.NET page? (untested)


Dim CN = New SqlConnection(ConfigurationSettings.AppSettings("connectionstring"))
Dim CM As New SqlCommand("exec spCCF_CrossTab @.LocationID = N'CCFIF', @.BeginDate = N'11/3/2003', @.EndDate = N'11/4/2003'", CN)
CM.CommandType = CommandType.Text
CN.Open()
DR = CM.ExecuteReader(CommandBehavior.CloseConnection)
dgReport.DataSource = DR
dgReport.DataBind()

Does this return the expected result?

Terri|||No. Query analyzer doesn't like this either (error 203 invalid identifier). HOWEVER, when I put this line back in the SP with the word 'END'


SELECT @.sql='', @.sumfunc=stuff(@.sumfunc, len(@.sumfunc), 1, ' End )' )

Query analyzer works just fine with:
exec spCCF_CrossTab @.LocationID = N'CCFIF', @.BeginDate = N'11/3/2003', @.EndDate = N'11/4/2003'

What the aspx page does:
without the word End I get error 203 invalid identifier.
With End I get the syntax error again "Incorrect syntax near the keyword 'End'."

The problem is I have to have about 8 different aspx pages that are going to need similar cross tab type reports - and I want to make the pages and code so I don't have to modify the aspx pages everytime there is a staff change. I can handle simple stored procedures but I really don't understand what is going on in this one enough to trouble shoot very well.

I appreciate your help in trying to get this worked out.|||For grins and giggles, what happens when you present the dates in ISO format?

exec spCCF_CrossTab @.LocationID = N'CCFIF', @.BeginDate = N'20031103', @.EndDate = N'20031104'

Terri|||Tried that - still an error.
I decided to start from scratch - took just the code for the stored procedure and added a simple select statement.

Still the same darn error with the END. Removing it - I get a cross tab table - but the values are a sum of all the values for that row - I get a table that each row has the same value in each column. I see the importance of the END, have been reading up on the stuff function, but still can't get this to work.

Since I don't have a DBA accessible, I may have to (ugh!) go to a case statement and figure out how I will manage changing staff.|||If you are still having trouble, script out all of your tables, and provide some data via a series of INSERT statements. This one is really tough to help with without having the real "stuff" to mess with.

Terri|||I was able to make the scripts for the tables, but is there a tool for doing the inserts?
I found some different code for doing the cross tabs. Does the same thing: works fine from QA, but get a SQL syntax error "Incorrect syntax at keyword 'END'" from the aspx page.

I tried this on a sample database with sample code provided (copied the code, didn't even retype) - same exact situation: works in query analyzer, syntax error with the aspx page.

I'm really doubting the problem is in the code since I have had a number of circumstances where this works in QA. Could the problem be in the version of the framework or .NET? I'm using Visual Studio 2002, 1.0 of the framework.


CREATE PROCEDURE crosstabextended

@.select_stmt varchar(8000),
@.groupfn varchar(100),
@.pivot_column varchar(100),
@.output_table varchar(100),
@.select_table varchar(100)
AS

DECLARE @.sql varchar(8000)
DECLARE @.delimiter varchar(1)

SET NOCOUNT ON
SET ANSI_WARNINGS OFF

DROP TABLE ##pivot

EXEC ('SELECT ' + @.pivot_column + ' AS pivot INTO ##pivot FROM ' + @.select_table + ' WHERE 1=2')

EXEC ('INSERT INTO ##pivot SELECT DISTINCT ' + @.pivot_column + ' FROM ' + @.select_table + ' WHERE '
+ @.pivot_column + ' Is Not Null' )

-- Add the string END to the group function (@.groupfn) variable
SELECT @.sql='', @.groupfn=stuff(@.groupfn, len(@.groupfn), 1, ' END)' )

--Check if pivot column starts with char or date

SELECT @.delimiter=CASE SIGN( CHARINDEX('char', data_type)+CHARINDEX('date', data_type) )
WHEN 0 THEN '' ELSE '''' END
FROM tempdb.information_schema.columns
WHERE table_name='##pivot' AND column_name='pivot'

SELECT @.sql=@.sql + '''' + CONVERT(varchar(100), pivot) + ''' = ' +
STUFF(@.groupfn,CHARINDEX( '(', @.groupfn )+1, 0, ' CASE ' + @.pivot_column + ' WHEN '
+ @.delimiter + CONVERT(varchar(100), pivot) + @.delimiter + ' THEN ' ) + ', ' FROM ##pivot

SELECT @.sql=LEFT(@.sql, LEN(@.sql)-1)

SELECT @.select_stmt=STUFF(@.select_stmt, CHARINDEX(' FROM ', @.select_stmt)+1, 0, ', ' + @.sql + ' ')

SELECT @.select_stmt=REPLACE(@.select_stmt, ' FROM', 'INTO '+ @.output_table + ' FROM')

IF EXISTS(SELECT table_name FROM tempdb.information_schema.tables WHERE table_name = @.output_table)
BEGIN
EXECUTE('DROP TABLE ' + @.output_table)
END

EXEC (@.select_stmt)

EXECUTE('SELECT * FROM ' + @.output_table)
SET ANSI_WARNINGS ON
GO


Code used in aspx page:

Dim CN1 = New SqlConnection(ConfigurationSettings.AppSettings("TestString"))
Dim CM As New SqlCommand("execute crosstabextended 'select Store_name as StoreName from storemaster inner join sales on (sales.store_id=storemaster.store_id) group by store_name', 'sum(qty)', 'toy_id', '##mytemp', 'toymaster'", CN1)
CM.CommandType = CommandType.Text
CN1.Open()
Dim da As SqlDataAdapter
da = New SqlDataAdapter(CM)
da.Fill(dsData)

Thanks!|||Did you ever find a solution to this problem?

error with SQL statement

hi, i try the below sql code, however when i try to execute the command, it always give me the error 'Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.'

If i remove the "(SELECT [description] = CASE WHEN ([description]) <> '' THEN [description] ELSE [tbl_batch_completed].[status] END)" under the group by clause, it will work

do I need to change something in the sql statement?

Thanks in advance

SELECT TAG_FACE_CON.REQUEST_ID,
(SELECT [description] = CASE WHEN ([description]) <> '' THEN [description] ELSE [tbl_batch_completed].[status] END)AS status

FROM (TAG_FACE_CON RIGHT JOIN tbl_batch_completed ON TAG_FACE_CON.GROUP_ID = tbl_batch_completed.ID)
GROUP BY TAG_FACE_CON.REQUEST_ID,(SELECT [description] = CASE WHEN ([description]) <> '' THEN [description] ELSE [tbl_batch_completed].[status] END)

You are going to have to remove the select staement from the group by. Also in that SQl Staement there is no from clause... It does not know where to get the batch completed information.

I would look into create a temp table to create the first section as raw data, then when you need to do the group by run it as a query from the temp table.|||I think restructuring your query like this will solve your problem:


SELECT
TAG_FACE_CON.REQUEST_ID,
CASE
WHEN [description] <> '' THEN [description]
ELSE [tbl_batch_completed].[status]
END AS status
FROM
TAG_FACE_CON
RIGHT JOIN
tbl_batch_completed ON TAG_FACE_CON.GROUP_ID = tbl_batch_completed.ID
GROUP BY
TAG_FACE_CON.REQUEST_ID,
CASE
WHEN [description] <> '' THEN [description]
ELSE [tbl_batch_completed].[status]
END

Terri

Sunday, February 26, 2012

error with connection with SQL SERVER

Hi

I am developing web application.

I have connected my app. with sql server using web.config as code given below using Named pipe connection

<appSettings>
<add key="constring" value="Server=ebserver;UID=sa;database=Airport-Clearance;Integrated Security=SSPI;network library=dbnmpntw;" />
</appSettings
After than i have added a new CLASS in my app.
in that, I have written as given below code.

public SqlConnection GetConnection()
{
System.Configuration.AppSettingsReader objApp = new System.Configuration.AppSettingsReader ();
SqlConnection sqlconn = new SqlConnection ();
sqlconn.ConnectionString = Convert.ToString(objApp.GetValue("constring", typeof(string)));
return sqlconn ;
}

Finally, In load event of form, I have written as below code.

Class1 objcs = new Class1() ;
SqlConnection sqlconn = objcs.GetConnection ();
SqlDataAdapter filling = new SqlDataAdapter("select * from Airport",sqlconn);
DataSet ds = new DataSet();
sqlconn.Open();
//filling.Fill(ds,"Airport");

//DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables["Airport"];
dg.DataBind();
//Do what ever
sqlconn.Close ();

When i run this application

It gives error like

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

If i use try catch then it doesnt display any error.but Even it doesnt display datagrid on form.

Please give me solution.

Even how to run app. line by line as we run in VB using F8.

Reply please,

Regards,
ASIFTry this instead (assuming you're not using beta version):

public SqlConnection GetConnection()
{
SqlConnection sqlconn = new SqlConnection ();
sqlconn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ConnectionString;
return sqlconn ;
}

Error with a simple JOIN query....

Hi!

I've a big problem by using the following query :

Code Snippet

public SqlCeResultSet selectRSQuery(String query)

{

SqlCeResultSet resultSet = initializeCommand(query).ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);

return resultSet;

}

SqlCeResultSet resultSet = sgb.selectRSQuery(

"SELECT p.pId, p.pLogin FROM Profiles p, ProfilesGroups pg, Groups g " +

"WHERE g.gId = pg.tpGroupId " +

"AND p.pId = pg.tpProfileId " +

"AND g.gProfileID = '" + app.Settings.Default.id + "'");

It return me this error :

Cannot generate an updatable cursor for the query because there is a non-standard join expression.

What can I do?

Thxx

Try using ANSI joins?

public SqlCeResultSet selectRSQuery(String query)

{

SqlCeResultSet resultSet = initializeCommand(query).ExecuteResultSet(ResultSetOptions.Scrollable | ResultSetOptions.Updatable);

return resultSet;

}

SqlCeResultSet resultSet = sgb.selectRSQuery(

"SELECT p.pId, p.pLogin

FROM Profiles p

inner join ProfilesGroups pg on pg.tpProfileID = p.pld

inner join Groups g on g.gld = pg.tpProfileId" +

"WHERE g.gProfileID = '" + app.Settings.Default.id + "'");

|||

hello!

I tried it... and it returns me :

Cannot generate an updatable cursor for the query because there is no updatable column.

thx for help

|||

re

if I remove the Options of the resultset.... It works..... but then It says me :

This operation is not valid because the cursor is not scrollable.

when I bind the resultset to my ListView :

lstViewTest.DataContext = resultSet;

edit : Here is the explanation of the problem :

Forward-only/Read-only Cursors

Forward-only/read-only cursors, referred to as forward-only cursors in earlier versions of SQL Server Compact Edition, are the fastest cursors, but cannot be updated.

The following is an example of how to obtain a forward-only/read-only cursor by using ADO.NET:

cmd.CommandText = "Select * from tablename";

SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.None);

Note You cannot create read-only cursors on query that returns only read only columns because internally all SQL Server Compact Edition cursors are updatable. SQL Server Compact Edition cannot update read-only columns returned in the SqlCeResultSet. Therefore, it would fail with the error "Cannot generate an updatable cursor for the query because there is no updatable column."

|||

how can I fill my ListView without using a ResultSet ?

thx...

|||ExecuteReader returns a DataReader that can be fed to the DataTable.Load. Either that or create a DataAdapter and use the Fill method to create a DataTable. Bind the DataTable to the list.|||

Hi!

I decided to use ObservableCollection! I load my objects with a sqlcedatareader in a ObservableCollection, and then bind it in xaml mode!

The disadvantage of this method is that I lost "the design preview" in Blend

Here is my code :

Code Snippet

public class ProfileI : INotifyPropertyChanged

{

private String _id;

private String _profileInfoID;

private String _login;

private String _password;

public ProfileI() { }

public ProfileI(string id, string profileInfoID, string login)

{

Id = id;

ProfileInfoID = profileInfoID;

Login = login;

}

public ProfileI(string id, string profileInfoID, string login, string password)

{

Id = id;

ProfileInfoID = profileInfoID;

Login = login;

Password = password;

}

#region Properties Getters/Setters

public String Login

{

get

{

return _login;

}

set

{

if (value != "")

{

if (value.Length < 5)

{

throw new ArgumentException(app.Resources.errorLoginTooSmall);

}

_login = value;

OnPropertyChanged("Login");

}

}

}

public String Password

{

get

{

return _password;

}

set

{

if (value != "")

{

if (value.Length < 5)

{

throw new ArgumentException(app.Resources.errorLoginTooSmall);

}

_password = value;

OnPropertyChanged("Password");

}

}

}

public string ProfileInfoID

{

get

{

return _profileInfoID;

}

set

{

_profileInfoID = value;

OnPropertyChanged("ProfileInfoID");

}

}

public string Id

{

get

{

return _id;

}

set

{

_id = value;

OnPropertyChanged("Id");

}

}

#endregion

public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(String propertyName)

{

if (this.PropertyChanged != null)

PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

}

}

public class myProfilesI :

ObservableCollection<ProfileI>

{

public myProfilesI()

{

// On r?cup?re les "profiles-amis" de l'utilisateur

SingleDatabase sd = SingleDatabase.getInstance();

SqlCeDataReader sdr = sd.selectDRQuery(

"SELECT p.pId, p.pProfileInfoID, p.pLogin FROM Profiles p, ProfilesGroups pg, Groups g " +

"WHERE g.gId = pg.tpGroupId " +

"AND p.pId = pg.tpProfileId " +

"AND g.gProfileID = '" + app.Settings.Default.id + "'");

while (sdr.Read())

{

Add(new ProfileI(sdr["pId"].ToString(), sdr["pProfileInfoID"].ToString(), sdr["pLogin"].ToString()));

}

}

}

And my XAML file :

Code Snippet

<Window

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:d="http://schemas.microsoft.com/expression/blend/2006"

xmlns:ToDo="clr-namespace:ToDo"

x:Class="ToDo.ToDoConfig"

x:Name="Window"

Title="ToDoConfig"

Width="640" Height="480">

<Window.Resources>

<ObjectDataProvider x:Key="MyProfilesInfoDataSource"

ObjectType="{x:Type ToDo:myProfilesI}"/>

</Window.Resources>

<Grid x:Name="LayoutRoot">

<Grid.RowDefinitions>

<RowDefinition Height="0.169*"/>

<RowDefinition Height="0.831*"/>

<RowDefinition Height="30"/>

</Grid.RowDefinitions>

<ToDo:Footer HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Grid.Row="2"/>

<ToDo:Header HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Grid.RowSpan="1"/>

<ListView ItemsSource="{Binding Source={StaticResource MyProfilesInfoDataSource}}" IsSynchronizedWithCurrentItem="True" Grid.Row="1">

<ListView.View>

<GridView>

<GridViewColumn DisplayMemberBinding=

"{Binding Path=Login}"

Header="Login" Width="100"/>

</GridView>

</ListView.View>

</ListView>

</Grid>

</Window>

Also note that it's not possible to use construtors like this :

Code Snippet

public ProfileI(string id, string profileInfoID, string login)

: this(id, profileInfoID, login, null)

{}

public ProfileI(string id, string profileInfoID, string login, string password)

{

Id = id;

ProfileInfoID = profileInfoID;

Login = login;

Password = password;

}

If you have a solution to conserve the design in Blend, I will be happy .

+++

Friday, February 24, 2012

error while using distinct top with Order By

I am trying to run a simple query
select DISTINCT TOP 10 email,code from user_info where code like 'xx12%'
ORDER BY x_date desc
I get this error-
Server: Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specifie
d.
Can anyone help?select DISTINCT TOP 10 email, code, x_date
from user_info where code like 'xx12%'
ORDER BY x_date desc
AMB
"Mike" wrote:

> I am trying to run a simple query
> select DISTINCT TOP 10 email,code from user_info where code like 'xx12%'
> ORDER BY x_date desc
> I get this error-
> Server: Msg 145, Level 15, State 1, Line 1
> ORDER BY items must appear in the select list if SELECT DISTINCT is specif
ied.
> Can anyone help?
>|||Some backgrouung info from celko:
http://groups.google.de/groups?hl=d...r />
2540tk2ms
ftngp13.phx.gbl%26rnum%3D1
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Mike" <Mike@.discussions.microsoft.com> schrieb im Newsbeitrag
news:FFEDAF14-77CE-46C1-AA15-363D99E265C6@.microsoft.com...
>I am trying to run a simple query
> select DISTINCT TOP 10 email,code from user_info where code like 'xx12%'
> ORDER BY x_date desc
> I get this error-
> Server: Msg 145, Level 15, State 1, Line 1
> ORDER BY items must appear in the select list if SELECT DISTINCT is
> specified.
> Can anyone help?
>|||The error message seems clear. You need to put x_Date in the Select statemen
t
like so:
Select Distinct TOP 10 x_Date, Email, Code
From User_Info
Where Code Like 'xx12%'
Order By x_Date Desc
Thomas
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:FFEDAF14-77CE-46C1-AA15-363D99E265C6@.microsoft.com...
>I am trying to run a simple query
> select DISTINCT TOP 10 email,code from user_info where code like 'xx12%'
> ORDER BY x_date desc
> I get this error-
> Server: Msg 145, Level 15, State 1, Line 1
> ORDER BY items must appear in the select list if SELECT DISTINCT is specif
ied.
> Can anyone help?
>|||you should put x_date in the select if it is used in the order by clause
SELECT DISTINCT TOP 10 email, code, x_date
FROM user_info
WHERE code LIKE 'xx12%'
ORDER BY x_date DESC
Ilyan Mishiyev
IGM Consulting Corporation
Enterprise Web Solutions
www.igmcc.com
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:FFEDAF14-77CE-46C1-AA15-363D99E265C6@.microsoft.com...
>I am trying to run a simple query
> select DISTINCT TOP 10 email,code from user_info where code like 'xx12%'
> ORDER BY x_date desc
> I get this error-
> Server: Msg 145, Level 15, State 1, Line 1
> ORDER BY items must appear in the select list if SELECT DISTINCT is
> specified.
> Can anyone help?
>|||You can put x_date in the SELECT list, as suggested by other posters, but
what I think you are after is:
select TOP 10 email,code
from user_info
where code like 'xx12%'
GROUP BY email,code
ORDER BY MIN(x_date) desc
Jacco Schalkwijk
SQL Server MVP
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:FFEDAF14-77CE-46C1-AA15-363D99E265C6@.microsoft.com...
>I am trying to run a simple query
> select DISTINCT TOP 10 email,code from user_info where code like 'xx12%'
> ORDER BY x_date desc
> I get this error-
> Server: Msg 145, Level 15, State 1, Line 1
> ORDER BY items must appear in the select list if SELECT DISTINCT is
> specified.
> Can anyone help?
>

Error while trying to get predictions from relational DB

I am trying to get predictions and insert them into a DB table.

Following is the code I am using , but I am getting an error saying

'

An error occurred while preparing the query

,

Pl. help.

begin

declare @.v_query varchar(5000);
declare @.full_query varchar(5000);
declare @.v_dbquery varchar (200);

set @.v_dbquery = char(39)+'SELECT
[ProspectAlternateKey],
[FirstName],
[LastName],
[MaritalStatus],
[Gender],
[YearlyIncome],
[TotalChildren],
[NumberChildrenAtHome],
[HouseOwnerFlag],
[NumberCarsOwned]
FROM
[dbo].[ProspectiveBuyer]'+char(39);

set @.v_query = 'SELECT
[TM_Cluster].[Bike Buyer],
t.[ProspectAlternateKey],
PredictProbability([TM_Cluster].[Bike Buyer])
From
[TM_Cluster]
PREDICTION JOIN
OPENQUERY([Adventure Works DW],@.v_dbquery) AS t
ON
[TM_Cluster].[Marital Status] = t.[MaritalStatus] AND
[TM_Cluster].[Gender] = t.[Gender] AND
[TM_Cluster].[Yearly Income] = t.[YearlyIncome] AND
[TM_Cluster].[Total Children] = t.[TotalChildren] AND
[TM_Cluster].[Number Children At Home] = t.[NumberChildrenAtHome] AND
[TM_Cluster].[House Owner Flag] = t.[HouseOwnerFlag] AND
[TM_Cluster].[Number Cars Owned] = t.[NumberCarsOwned]'
-- print @.v_query

set @.full_query = 'select * from openquery (DMserver,'+char(39)+ @.v_query +char(39)+')' ;

print @.full_query;

EXEC (@.full_query);


end

Are you able to execute other DMX/MDX queries against the linked server to AS?

If not, you may need to make sure the MSOLAP provider is allowed in-proc on your SQL Server 2005 database engine instance. You can do this via SQL Server Management Studio - connect to the database engine, navigate to Server Objects -> Linked Servers -> Providers in the Object Explorer, right-click on MSOLAP to select Properties and check the "Allow inprocess" provider option.

|||

Yes, I was able to run DMX queries against the linked server.

For that purpose I had to check 'Allow Inprocess' as well as I had to go to linked server properties and in server option I had to set Rpc = True.

|||

You had some syntax errors that cause the query to fail (first in T-SQL and then in DMX) - see my comments marked "Raman:" in the corrected query below ( this one ran successfully on my machine):

begin

declare @.v_query varchar(5000);

declare @.full_query varchar(5000);

declare @.v_dbquery varchar (500); -- Raman: you had varchar(200) which was too small for the query

set @.v_dbquery = char(39) + -- Raman: need to escape the enclosing quotes when sending to AS as well

char(39)+'SELECT

[ProspectAlternateKey],

[FirstName],

[LastName],

[MaritalStatus],

[Gender],

[YearlyIncome],

[TotalChildren],

[NumberChildrenAtHome],

[HouseOwnerFlag],

[NumberCarsOwned]

FROM

[dbo].[ProspectiveBuyer]'+char(39)+char(39); -- Raman: need to escape the enclosing quotes when sending to AS as well

set @.v_query = 'SELECT

[TM Clustering].[Bike Buyer],

t.[ProspectAlternateKey],

PredictProbability([TM Clustering].[Bike Buyer])

From

[TM Clustering]

PREDICTION JOIN

OPENQUERY([Adventure Works DW],'

+ @.v_dbquery + -- Raman: @.v_dbquery needs to appended - you had it in the query string where it will not get substituted

')AS t

ON

[TM Clustering].[Marital Status] = t.[MaritalStatus] AND

[TM Clustering].[Gender] = t.[Gender] AND

[TM Clustering].[Yearly Income] = t.[YearlyIncome] AND

[TM Clustering].[Total Children] = t.[TotalChildren] AND

[TM Clustering].[Number Children At Home] = t.[NumberChildrenAtHome] AND

[TM Clustering].[House Owner Flag] = t.[HouseOwnerFlag] AND

[TM Clustering].[Number Cars Owned] = t.[NumberCarsOwned]'

--print @.v_query

set @.full_query = 'select * from openquery (DMserver,'+char(39)+ @.v_query +char(39)+')' ;

print @.full_query;

EXEC (@.full_query);

end

Error while trying to get predictions from relational DB

I am trying to get predictions and insert them into a DB table.

Following is the code I am using , but I am getting an error saying

'

An error occurred while preparing the query

,

Pl. help.

begin

declare @.v_query varchar(5000);
declare @.full_query varchar(5000);
declare @.v_dbquery varchar (200);

set @.v_dbquery = char(39)+'SELECT
[ProspectAlternateKey],
[FirstName],
[LastName],
[MaritalStatus],
[Gender],
[YearlyIncome],
[TotalChildren],
[NumberChildrenAtHome],
[HouseOwnerFlag],
[NumberCarsOwned]
FROM
[dbo].[ProspectiveBuyer]'+char(39);

set @.v_query = 'SELECT
[TM_Cluster].[Bike Buyer],
t.[ProspectAlternateKey],
PredictProbability([TM_Cluster].[Bike Buyer])
From
[TM_Cluster]
PREDICTION JOIN
OPENQUERY([Adventure Works DW],@.v_dbquery) AS t
ON
[TM_Cluster].[Marital Status] = t.[MaritalStatus] AND
[TM_Cluster].[Gender] = t.[Gender] AND
[TM_Cluster].[Yearly Income] = t.[YearlyIncome] AND
[TM_Cluster].[Total Children] = t.[TotalChildren] AND
[TM_Cluster].[Number Children At Home] = t.[NumberChildrenAtHome] AND
[TM_Cluster].[House Owner Flag] = t.[HouseOwnerFlag] AND
[TM_Cluster].[Number Cars Owned] = t.[NumberCarsOwned]'
-- print @.v_query

set @.full_query = 'select * from openquery (DMserver,'+char(39)+ @.v_query +char(39)+')' ;

print @.full_query;

EXEC (@.full_query);


end

Are you able to execute other DMX/MDX queries against the linked server to AS?

If not, you may need to make sure the MSOLAP provider is allowed in-proc on your SQL Server 2005 database engine instance. You can do this via SQL Server Management Studio - connect to the database engine, navigate to Server Objects -> Linked Servers -> Providers in the Object Explorer, right-click on MSOLAP to select Properties and check the "Allow inprocess" provider option.

|||

Yes, I was able to run DMX queries against the linked server.

For that purpose I had to check 'Allow Inprocess' as well as I had to go to linked server properties and in server option I had to set Rpc = True.

|||

You had some syntax errors that cause the query to fail (first in T-SQL and then in DMX) - see my comments marked "Raman:" in the corrected query below ( this one ran successfully on my machine):

begin

declare @.v_query varchar(5000);

declare @.full_query varchar(5000);

declare @.v_dbquery varchar (500); -- Raman: you had varchar(200) which was too small for the query

set @.v_dbquery = char(39) + -- Raman: need to escape the enclosing quotes when sending to AS as well

char(39)+'SELECT

[ProspectAlternateKey],

[FirstName],

[LastName],

[MaritalStatus],

[Gender],

[YearlyIncome],

[TotalChildren],

[NumberChildrenAtHome],

[HouseOwnerFlag],

[NumberCarsOwned]

FROM

[dbo].[ProspectiveBuyer]'+char(39)+char(39); -- Raman: need to escape the enclosing quotes when sending to AS as well

set @.v_query = 'SELECT

[TM Clustering].[Bike Buyer],

t.[ProspectAlternateKey],

PredictProbability([TM Clustering].[Bike Buyer])

From

[TM Clustering]

PREDICTION JOIN

OPENQUERY([Adventure Works DW],'

+ @.v_dbquery + -- Raman: @.v_dbquery needs to appended - you had it in the query string where it will not get substituted

')AS t

ON

[TM Clustering].[Marital Status] = t.[MaritalStatus] AND

[TM Clustering].[Gender] = t.[Gender] AND

[TM Clustering].[Yearly Income] = t.[YearlyIncome] AND

[TM Clustering].[Total Children] = t.[TotalChildren] AND

[TM Clustering].[Number Children At Home] = t.[NumberChildrenAtHome] AND

[TM Clustering].[House Owner Flag] = t.[HouseOwnerFlag] AND

[TM Clustering].[Number Cars Owned] = t.[NumberCarsOwned]'

--print @.v_query

set @.full_query = 'select * from openquery (DMserver,'+char(39)+ @.v_query +char(39)+')' ;

print @.full_query;

EXEC (@.full_query);

end

Sunday, February 19, 2012

Error while Running SQL Reporting Services

Hi,
I have recently installed SQL Reporting Service for SQL 2005 and started using it. I have one existing code that was using reporting services. But when now I try to run application it gives following error:
=============================================================
The request failed with HTTP status 503: Service Unavailable.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP status 503: Service Unavailable.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[WebException: The request failed with HTTP status 503: Service Unavailable.]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +533199
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
Ti.Dosa.Reports.ReportingServices.ReportingService.Render(String Report, String Format, String HistoryID, String DeviceInfo, ParameterValue[] Parameters, DataSourceCredentials[] Credentials, String ShowHideToggle, String& Encoding, String& MimeType, ParameterValue[]& ParametersUsed, Warning[]& Warnings, String[]& StreamIds) +175
Ti.UIWeb.NDD.ReportViewer.RenderReport(String[] reportParmsStr, String reportLocation, String reportFormat) +525
Ti.UIWeb.NDD.ReportViewer.Page_Load(Object sender, EventArgs e) +467
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
=============================================================
Please let me know what might be the problem.

Thanks,
Deepak

sounds to me like your website is running.

Did you run the ssrs setup tool?

|||Yes, Web Site is running but when I try access functionality which is using Reporting Services the mentioned error is popping up and yes, I have executed ssrs setup tool

--Deepak

Error While Running Dts

Hi,
I am trying to run a DTS from SP. The SQL code that I am using is as follows.......

exec master..xp_cmdshell 'dtsrun /S 142.102.27.207 /U sa /P sa /N DTS_TEST1'

But Running this I am getting the the following errror......
DTSRun: Loading...
DTSRun: Executing...
DTSRun OnStart: DTSStep_DTSDataPumpTask_1
DTSRun OnError: DTSStep_DTSDataPumpTask_1, Error = -2147467259 (80004005)
Error string: Error opening datafile: The system cannot find the path specified.
Error source: Microsoft Data Transformation Services Flat File Rowset Provider
Help file: DTSFFile.hlp
Help context: 0

Error Detail Records:
Error: 3 (3); Provider Error: 3 (3)
Error string: Error opening datafile: The system cannot find the path specified.
Error source: Microsoft Data Transformation Services Flat File Rowset Provider

Help file: DTSFFile.hlp
Help context: 0

DTSRun OnFinish: DTSStep_DTSDataPumpTask_1
DTSRun: Package execution complete.

NULLGuys......... Help me in this regard..............|||Is the SQL Instance your connecting to (142.102.27.207) local (the same server where you're running DTSRun)?

Also it's running from the context of the windows-account that's running SQL Server. Is that account allowed to access the file?|||The SqlServer Computer has been given the full control to the file where the data is to be transferred in the application server through DTS.|||where as when I am running from the command prompt of the application server, its running successfully...............

dtsrun /S 142.102.27.207 /U sa /P sa /N DTS_TEST1

NOTE:
SQLSERVER: 142.102.27.207
APPLICATION SERVER: 142.102.27.154

I have a folder named "TEST" in the application server, where i have given the "full control" to 142.102.27.207 (DB Server). Folder Test is having an excel file which is the destination object for the DTS. DTS is transferring teh data from a table to this excel file.|||it is definitly security related. Does the account running the sql server agent and sql server service have full control on test?

Friday, February 17, 2012

Error while loading code module

I have created a custom assembly and referenced it. The class can be
instantiated, so I have specified the class and instance name.
So, when I build the solution, the compiler returns these errors:
Error while loading code module: â'XXX, Version=Y.Y.YYYY.YYYYY
Culture=neutral, PublicKeyToken=nullâ'. Details: File or assembly name XXX, or
one of its dependencies, was not found.
Should there be a directory that this assembly be placed? As a test, I
placed the .dll in the GAC and experieced the same error.
Any help would be appreciated.
Thanks - JMLYes, you must place dll file in
\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin
directory
Regards
"AgentSmith" <AgentSmith@.discussions.microsoft.com> escribió en el mensaje
news:754CB514-27F9-40F3-82EE-6D46D143DB05@.microsoft.com...
> I have created a custom assembly and referenced it. The class can be
> instantiated, so I have specified the class and instance name.
> So, when I build the solution, the compiler returns these errors:
> Error while loading code module: 'XXX, Version=Y.Y.YYYY.YYYYY
> Culture=neutral, PublicKeyToken=null'. Details: File or assembly name XXX,
or
> one of its dependencies, was not found.
> Should there be a directory that this assembly be placed? As a test, I
> placed the .dll in the GAC and experieced the same error.
> Any help would be appreciated.
> Thanks - JML
>|||What if the report server is not on your machine? Should I just create the
directory?
"plmartinez" wrote:
> Yes, you must place dll file in
> \Microsoft SQL Server\MSSQL\Reporting Services\ReportServer\bin
> directory
> Regards
> "AgentSmith" <AgentSmith@.discussions.microsoft.com> escribió en el mensaje
> news:754CB514-27F9-40F3-82EE-6D46D143DB05@.microsoft.com...
> > I have created a custom assembly and referenced it. The class can be
> > instantiated, so I have specified the class and instance name.
> >
> > So, when I build the solution, the compiler returns these errors:
> >
> > Error while loading code module: 'XXX, Version=Y.Y.YYYY.YYYYY
> > Culture=neutral, PublicKeyToken=null'. Details: File or assembly name XXX,
> or
> > one of its dependencies, was not found.
> >
> > Should there be a directory that this assembly be placed? As a test, I
> > placed the .dll in the GAC and experieced the same error.
> >
> > Any help would be appreciated.
> >
> > Thanks - JML
> >
>
>

Wednesday, February 15, 2012

error while connecting

Hey all,

I am new to ASP.NET. While executing a simple code , i got the error:System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.

Whats wrong?

Regards

Yasir

Maybe the problem is in your connection string or you don't open database connection when executing data manipulating.Please check this again.If you still have a problem.please paste your code here.