Showing posts with label studio. Show all posts
Showing posts with label studio. Show all posts

Wednesday, March 28, 2012

How to get the returning value of a stored procedure?

Hi everyone!
I am new to sql server 2005 and visual studio 2005.

I have the following simple stored procedure that checks if a user exists:
-------------------------------
ALTER PROCEDURE [dbo].[sp_Users_AlreadyExists]

@.UserName varchar(256)
AS
BEGIN
SET NOCOUNT ON;


IF (EXISTS (SELECT UserName FROM dbo.Users WHERE LOWER(@.UserName) = LoweredUserName ))
RETURN(1)
ELSE
RETURN(0)
END
-------------------------------

I use the following code to execute the procedure on visual studio:
-------------------------------
.
.
.
cmdobj As SqlCommand
cmdobj = New SqlCommand(sp_Users_AlreadyExists, connobj)
cmdobj.CommandType = CommandType.StoredProcedure
cmdobj.Parameters.AddWithValue("@.UserName", "blablalala")
cmdobj.ExecuteNonQuery()
cmdobj.Dispose()
connobj.Close()
.
.
.
-------------------------------

I expected that cmdobj.ExecuteNonQuery() would return 1 if the userblablab exists or 0 if the user doesnt, but it just return -1 (i thinkbecause no row was affected)

Does anyone knows how to retrieve the value that my stored procedure returns?

Thanx in advance!

cmdobj.parameters.add("@.RETURN_VALUE",sqldbtype.int).direction=returnvalue

Then check the parameter value after the execute like:

dim val as integer=cmdobj.parameters("@.RETURN_VALUE").value

sql

Monday, March 26, 2012

How to get the MDX query through Cube browser in BIDS?

Is there any means to get the MDX query generated internally when we browser the cube in Business Intilligence Development Studio (BIDS)?

Please let me know.

Thanks,

Austin.

SQL Server Profiler will let you capture query generated by BIDS.

Vidas Matelis

Monday, March 19, 2012

How to get started on Microsoft SQL Server Management Studio Express

Hi,

Was trying to open AdventureWorks when i got this error: "There is no editor available "C: Program Flies.....\AdventureWorksDW_Log.LDF'
Make sure the application for the file type(.LDF) is installed.
How can this error be corrected? I also have some error on mdf not installed.May i know how should be the initally steps to be done inorder for me to view this database.
And if i do have a database from microsoft access, what are the steps that i need to do inorder to get it export to Microsoft SQL Server Management Studio Express. Please advise as i really new to it. Thanks!

Hi,

if you want to let the database be controlled by the instance you will have to do a right click on the database node > Attach Database > Select the Database files. The instance will be automatically attached and you will be able to access the database through the server Explorer.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de
|||

Hi,

Thanks for the info.Btw, how do we attach access database which is mdb format?
The form design that i have in access database...can this be viewable in microsoft sql server management studio express. Please advise.

|||

Hi,

I have managed to attached the AdventureWorks data. But it seem like there are some restrictions. Must we set any rights to user so that we can view the AdventureWorks data? Please advise. Thanks.

|||

hi,

kumalla wrote:

Thanks for the info.Btw, how do we attach access database which is mdb format?
The form design that i have in access database...can this be viewable in microsoft sql server management studio express. Please advise.

you can not attach an Access database to a SQL Server instance... you have to use the Upsize Wizard or similar tool to import the JET db into a new SQL Server database..

regards

|||

hi,

kumalla wrote:

Hi,

I have managed to attached the AdventureWorks data. But it seem like there are some restrictions. Must we set any rights to user so that we can view the AdventureWorks data? Please advise. Thanks.

start reading BOL at http://msdn2.microsoft.com/en-us/library/ms187648.aspx .. you can there find the whole security architecture to understand permissions and requirements to connect to SQL Server instances, databases and individual objects and their data..

regards

How to get SQL Server Management Studio to automatically connect upon startup?

Hi all,
2000's Enterprise Manager was smart enough to automatically connect to my
last database when it was launched.
Somehow I can't find out how to turn on this extremely useful feature in
2005's Management Studio. Can anyone tell me the secret?
Thanks,
C17
> 2000's Enterprise Manager was smart enough to automatically connect to my
> last database when it was launched.
> Somehow I can't find out how to turn on this extremely useful feature in
> 2005's Management Studio. Can anyone tell me the secret?
None of these things are "secrets." You can add command line parameters and
create shortcuts for different servers. Here are the possible startup
parameters for Management Studio (sqlwb.exe):
Usage:
sqlwb.exe [-S server_name[\instance_name]] [-d database] [-U user] [-P
password] [-E] [file_name[, file_name]] [/?]
[-S The name of the SQL Server instance to which to connect]
[-d The name of the SQL Server database to which to connect]
[-E] Use Windows Authentication to login to SQL Server
[-U The name of the SQL Server login with which to connect]
[-P The password associated with the login]
[file_name[, file_name]] names of files to load
[-nosplash] Supress splash screen
[/?] Displays this usage information
However, this won't automatically open Object Explorer. (Same was true in
Query Analyzer, IIRC.)
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
|||Thank you, that works great!!
It's still annoying that one can't set a default via the UI, though. From
reading the Feedback pages, and the MSFT responses, it seems as though
everyone at MSFT thinks that we're all using Management Studio from inside
of VS, and so the response to a lot of these usability requests is
basically,
"Well, you can do that from inside of VS." I think they forget that a lot
of us use it for management, not development!
Thanks again,
C17
|||You maybe are misunderstanding the posts from Microsoft. You
don't use Management Studio from inside Visual Studio. You
use Management Studio OR Visual Studio.
What posts are you referring too? You are always free to
offer product suggestions.
-Sue
On Thu, 14 Jun 2007 14:41:07 -0400, "C17"
<c17@.community.nospam> wrote:

>Thank you, that works great!!
>It's still annoying that one can't set a default via the UI, though. From
>reading the Feedback pages, and the MSFT responses, it seems as though
>everyone at MSFT thinks that we're all using Management Studio from inside
>of VS, and so the response to a lot of these usability requests is
>basically,
>"Well, you can do that from inside of VS." I think they forget that a lot
>of us use it for management, not development!
>Thanks again,
>C17
>

Monday, March 12, 2012

How to Get RS Tools for Visual Studio 2003?

The overall question: How do I get the Reporting Services tools for Visual
Studio 2003 if my web hosting company owns the SQL Server?
I am a lone developer with a laptop and a web hosting company. I have Visual
Studio 2003 installed on my laptop (Windows XP Pro). My web host provides me
with .NET, SQL Server 2000, and now Reporting Services. I want to begin to
learn and use Reporting Services.
In searching Microsoft's web site, it seems that I can only obtain the tools
that go into Visual Studio to develop RS reports if I have my own SQL Server
2000. I own a copy of SQL Server 2000 Professional, but I cannot install it
on XP Pro. It requires a server version of Windows. I do have MSDE
installed, but Reporting Services (RSEval.exe) refuses to install on this
version. I don't have access to high priced things like an MSDN universal or
enterprise subscription. I don't qualify for academic versions.
There must be a way for developers like me to get the tools necessary to
create these reports. Any ideas?You do not need to install the server to use the tools (setup will warn you
but you can ignore it). The evaluation version should work fine for you.
--
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Rick" <rrgrimm@.hotmail.com> wrote in message
news:OjYVHZ2pEHA.2696@.TK2MSFTNGP15.phx.gbl...
> The overall question: How do I get the Reporting Services tools for Visual
> Studio 2003 if my web hosting company owns the SQL Server?
> I am a lone developer with a laptop and a web hosting company. I have
> Visual Studio 2003 installed on my laptop (Windows XP Pro). My web host
> provides me with .NET, SQL Server 2000, and now Reporting Services. I want
> to begin to learn and use Reporting Services.
> In searching Microsoft's web site, it seems that I can only obtain the
> tools that go into Visual Studio to develop RS reports if I have my own
> SQL Server 2000. I own a copy of SQL Server 2000 Professional, but I
> cannot install it on XP Pro. It requires a server version of Windows. I do
> have MSDE installed, but Reporting Services (RSEval.exe) refuses to
> install on this version. I don't have access to high priced things like an
> MSDN universal or enterprise subscription. I don't qualify for academic
> versions.
> There must be a way for developers like me to get the tools necessary to
> create these reports. Any ideas?
>

How to get Row Numbers from SQL Express 2005 query?

Hi,

I'm using SQL Express 2005 and VIsual Studio 2005, and this sounds like it should be easy. I'm trying to return the row numbers of my queries, but if I use the Row_Number() command I get the following error:

"The OVER SQL construct or statement is not supported."

So, is Row_Number() not supported in SQL Express 2005? If not, how can I return row numbers with my queries? Or, more specifically, how can I return a limited result set from a query (i.e. Return only row number 10-20)?

My current command is as follows:

SELECT (SELECT Row_Number()OVER (ORDER BY UserName)As RowNumber), *
FROM Users
ORDER BY UserName

Thanks for any advice you can offer!


like this

With Cust AS
( SELECT CustomerID, CompanyName,
ROW_NUMBER() OVER (order by CompanyName) as RowNumber
FROM Customers )
select *
from Cust
Where RowNumber Between 20 and 30

Hope this helps

|||

SELECT ROW_NUMBER() OVER (ORDER BY ProductID) as RowNumber,ProductID, ProductName, UnitPrice FROM Products WHERE RowNumber BETWEEN 20 AND 30;

|||

Thank you both for your replies. I'm sorry, I think I my question may have been a bit misleading. I know that you can return a limited result set by using the statements you have provided, but the error message I am getting is as follows:

"The OVER SQL construct or statement is not supported."

Both your suggestions use the OVER construct, and this does not appear to be supported bySQL Server Express 2005. If I run your suggested queries inVisual Studio 2005 I get the aforementioned error and the query will not run (though the SQL validation check says it's fine).

So, is the "Row_Number() OVER" command supported by SQL Express 2005 or not? If not, what other ways can I return a limited result set?

|||

i think you are using the designer, go in the sql server management studio and to this

Select File / New / Query and type your queries in the editing window instead.

Hope this helps

|||

Run this in SQL SERVER 2005 Management Studio Express:

EXEC sp_dbcmptlevel yourDataBase

If the current compatibility level of your database is 80, then run this:

EXEC sp_dbcmptlevel yourDataBase, 90


You need the compatibility level at 90 to run the Row_Number() OVER() query and other new features.

|||

Hi Limno,

That sounds promising. I've tried getting my website database into SQL Server Management Studio Express in the past but without success. My database is held as a .MDF file within my project - is there a way of importing this directly into Management Studio? The "Connect To Server" dialog displayed on startup does not allow me to browse to a specific .MDF file, and the File -> Open dialog has no option to open .MDF files.

Thanks

|||

I just found out how to import an MDF here:

http://forums.asp.net/p/1147899/1871779.aspx#1871779

And my database shows a compatibility rating of 90. Using the Row_Number() command works within SQL Server Management Express Studio! In that case, how can I perform a query in Visual Studio 2005 that uses this command if Visual Studio does not support this command?

I'm using strongly typed Table Adapters and Data Tables using the DAL component in Visual Studio. Is it impossible? If not, can I at least perform this query programmatically (C#) and cast the results to my strongly typed Data Table? If it can be done programmatically, does anyone have any examples of how to do this?

Thanks again!

|||

In Visual Studio 2005, you will see that not support message. Have you tried to ingnore it and see what will happen? It seems is should work fine. Another way, you can wrap your query in a Stored Procedure to work with.

How to get rid of unused servers in SSMS?

In Connect to Server dialog box in SQL Server Management Studio, it has a drop-down box with a list previously connected servers. However, some of these servers are not used anymore. I want to get rid of them in order to make a room for new server names. So far I could not find a way how to do this, apparently SQL Server does not store these values in the Registry. Is there a way to get rid of them ?

Thanks.

I looked earlier today for you and like you it appears the registry is not the "store" for this data. Upon looking through all of the "known" sql directories my hunch (though I cannot find it) would be that its somewhere at C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE.|||

You can blow away all your Most Recently Used lists (including MRU connections) by deleting c:\Documents and Settings\<you>\Application Data\Microsoft SQL Server\90\Tools\Shell\mru.dat while Management Studio is not running. Management Studio will recreate the file the next time it starts.

Hope this helps,
Steve

Wednesday, March 7, 2012

How to get MDX query that BI Studio generates in the Cube''s Browser

Hi,

I have been trying to write an MDX query which restricts the data based on a date range on the time dimension.

I am able to frame this query on the GUI interface of the Business Intelligence Studio (Using the cube browser) But I want the actual MDX for it.

To be specific, I am trying to view how the "Range (Inclusive") operator is implemented in the "Browser" Tab of the Cube Editor in the Business Intelligence Studio.

I have a Time dimension which has Year, Quarter, Month, Day Hierachy and I need to form the query such that I have a couple of pre-defined CALCULATED measures on the Column axis and Another dimension on the Row axis. I want to limit the records to a Range (Say Jan 1, 2007 to Aug 5, 2007).

My MDX works when it is for a single value of the Time Dimension.But for a range, I get nulls in the calculated measures.

My MDX is :

WITH

MEMBER [Time-By Calendar].[Time-By Calendar].[Selected Time] AS '

AGGREGATE({{[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1]:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1].parent.parent.lastChild.lastChild}

+ {[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1].parent.parent.nextMember:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5].parent.parent.prevMember}

+ {[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5].parent.parent.firstChild.firstChild:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5]}})

', SOLVE_ORDER = 5001, SCOPE_ISOLATION=CUBE

SELECT DISTINCT( {[Measures].[Available Hours], [Measures].[Agency] ) ON AXIS(0) ,

DISTINCT( {[Resource-By Pool].[Resource Name].members} ) on AXIS(1)

FROM [RESOURCE SUMMARY]

WHERE [Time-By Calendar].[Time-By Calendar].[Selected Time]

=====================================

Where the calculated MEASURE.Agency is pre-defined as:

CREATE MEMBER CURRENTCUBE.Measures.[Agency] AS

'IIF(NOT([Resource-By Pool].[Resource-By Pool].CurrentMember IS NULL) AND IsLeaf([Resource-By Pool].[Resource-By Pool].CurrentMember),

IIF(NONEMPTYCROSSJOIN({[Agency-By Pool].[Agency Pool].&[].&[0]},{[Resource-By Pool].[Resource-By Pool].CurrentMember}).count > 0,

"",NONEMPTYCROSSJOIN({[Agency-By Pool].[Agency Name].members},{[Resource-By Pool].[Resource-By Pool].CurrentMember}).item(0).item(0).name),"")', SOLVE_ORDER = 5000;

Any help is greatly appreciated.

Regards,

Mehernosh

I'm not entirely sure, but if I read your statement correctly all you are trying to achieve is to get the aggregate of the dates from Jan 1 to Aug 5. In which case you should be able to do the following.

SELECT {[Measures].[Available Hours], [Measures].[Agency] } ON AXIS(0) ,

{[Resource-By Pool].[Resource Name].members} on AXIS(1)

FROM [RESOURCE SUMMARY]

WHERE {[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1]:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5]}

And if you are after a YTD amount it could be expressed even more concisely as:

SELECT {[Measures].[Available Hours], [Measures].[Agency] } ON AXIS(0) ,

{[Resource-By Pool].[Resource Name].members} on AXIS(1)

FROM [RESOURCE SUMMARY]

WHERE {YTD([Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5])}

I'm not sure why you are using a measure for the agency name and not just crossjoining in the Agency dimension:

SELECT {[Measures].[Available Hours] } ON AXIS(0) ,

NON EMPTY {[Resource-By Pool].[Resource Name].members} *

{Agency-By Pool].[Agency Name].members} on AXIS(1)

FROM [RESOURCE SUMMARY]

WHERE {[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1]:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5]}

There are a couple of issues with your calculated measure. This statement "NOT ([Resource-By Pool].[Resource-By Pool].CurrentMember IS NULL)" will always return true as the IS operator does a member comparison not a value comparison and CurrentMember will always return a valid member. I think what you probably meant was "NOT IsEmpty(Resource-By Pool].[Resource-By Pool].CurrentMember)". But I would have thought including the Agency dimension in the row axis would have done a similar thing (unless agency &[0] has some other label)

|||

Hello Darren,

Thank you for your response. You are correct that I want the aggregate of the Hours for a Resource, but also want the value of the Agency dimension to be displayed along, BUT as a measure.

The MDX you provided, (with the cross join on Row Axis), certainly works. But alas I need the AGENCY to be a measure on the Column axis.

The reason is that our enterprise application has a customizable Portfolio management component (that uses Analysis Server) wherein Users can add/remove a set of predefined measures to their view. Very much like how the Cube browser does, but with limited functionality such that only predefined measures can be dropped on to the Column axis. And the ROWS are limited by Time dimension. The application generates the MDX based on the set of measures provided. Hence we need each measure to be declared separately as 'CREATE MEMBER CURRENTCUBE.Measures'.

Also the switch to using "NOT IsEmpty" instead of "NOT null" check in the definition of the Agency measure did not make any difference. The measure value still returns as null for each row.

The funny thing is that this query WORKs in AS2000. But as we were porting our application to use AS2005 we ran into this issue.

But I see that when I do a similar thing with the "Cube Browser", we get the correct result. (Agency is declared as a calculated measure on the cube)

Hence I wanted to see the MDX query that is generated by the Cube browser. Should I listen on any particular port to get the MDX that is sent to the Analysis Server. Is the traffic encoded

Any help will be highly appreciated as the porting of the application to AS2005 has stalled because of this issue

Regards,

Mehernosh

|||

Mehernosh Vadiwala wrote:

The funny thing is that this query WORKs in AS2000. But as we were porting our application to use AS2005 we ran into this issue.

You did not mention that this used to run under AS2000, on double checking the calc I noticed that you are referencing the [Resource-By Pool].[Resource-By Pool] attribute hierarchy. At the attribute hierarchy level there is usually a default "All" member so the count will always be 1. If you add an extra [Resouce-By Pool] reference to specify just the level in the attribute hierarchy with the actual members.

CREATE MEMBER CURRENTCUBE.Measures.[Agency] AS

'IIF(NOT([Resource-By Pool].[Resource-By Pool].CurrentMember IS NULL) AND IsLeaf([Resource-By Pool].[Resource-By Pool].CurrentMember),

IIF(NONEMPTYCROSSJOIN({[Agency-By Pool].[Agency Pool].&[].&[0]},{[Resource-By Pool].[Resource-By Pool].[Resource-By Pool].CurrentMember}).count > 0,

"",NONEMPTYCROSSJOIN({[Agency-By Pool].[Agency Name].members},{[Resource-By Pool].[Resource-By Pool].CurrentMember}).item(0).item(0).name),"")', SOLVE_ORDER = 5000;

Mehernosh Vadiwala wrote:

Hence I wanted to see the MDX query that is generated by the Cube browser. Should I listen on any particular port to get the MDX that is sent to the Analysis Server. Is the traffic encoded

Yes, the traffic is encoded, but you can use SQL Profiler to connect to SSAS in 2005 and see the begin and end query events which have most of the MDX, some of the cube browser controls create named sets within the session, so you might need to assemble the MDX from a couple of trace statements.

|||

Darren,

This query used to work in AS2000, but I had already ported it for AS2005. i.e. I had already added the additional hierarchy attribute. (If you notice, I already have [Resource-By Pool].[Resource-By Pool].currentMember in the query I gave above. The SQL2000 version had only [Resource-By Pool].currentMember )

But that was the only change I made to the Query.

Anyway I found the solution. All I had to do was not declare the slicer axis (WHERE clause) in place, instead of with a separate Member.

======= Not Working =================================

WITH

MEMBER [Time-By Calendar].[Time-By Calendar].[Selected Time] AS '

AGGREGATE({[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1]:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5})

', SOLVE_ORDER = 5000, SCOPE_ISOLATION=CUBE

SELECT DISTINCT( {[Measures].[Available Hours], [Measures].[Agency] ) ON AXIS(0) ,

DISTINCT( {[Resource-By Pool].[Resource Name].members} ) on AXIS(1)

FROM [RESOURCE SUMMARY]

WHERE [Time-By Calendar].[Time-By Calendar].[Selected Time]

======= WORKING =================================

SELECT DISTINCT( {[Measures].[Available Hours], [Measures].[Agency] ) ON AXIS(0) ,

DISTINCT( {[Resource-By Pool].[Resource Name].members} ) on AXIS(1)

FROM [RESOURCE SUMMARY]

WHERE ({[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 1].[January].[1]:[Time-By Calendar].[Time-By Calendar].[Year].&[2007].[Quarter 3].[August].[5})

=================================================

Any insight on why this works and not the other ?

Also I have a bigger issue coming up with "LookupCube" function. None of our calculated Measures that have the LookupCube function in them return any results now. In the documentation, there is just one line, stating that the implementation of LookupCube has changed. There is no additional information.

Could this be the reason? Is there some documentation on this ?

Mehernosh

|||

Mehernosh Vadiwala wrote:

This query used to work in AS2000, but I had already ported it for AS2005. i.e. I had already added the additional hierarchy attribute. (If you notice, I already have [Resource-By Pool].[Resource-By Pool].currentMember in the query I gave above. The SQL2000 version had only [Resource-By Pool].currentMember )

Sorry, you're right the formula has already been adjusted correctly.

Mehernosh Vadiwala wrote:

Anyway I found the solution. All I had to do was not declare the slicer axis (WHERE clause) in place, instead of with a separate Member.

Yeah, that was what I suggested in my first response.

Mehernosh Vadiwala wrote:

Any insight on why this works and not the other ?

The only reason I could think that this might have issues would be if you [available hours] measure is calculated and relies on having a [Time-by Calendar] context. A cacluated aggregate in the query will not supply such a context and the formula would calculate as if it were at the all level. The Aggregate function is meant to calculate early in the solve order, but your setting of the solve order may be overriding this.

Mehernosh Vadiwala wrote:

Also I have a bigger issue coming up with "LookupCube" function. None of our calculated Measures that have the LookupCube function in them return any results now. In the documentation, there is just one line, stating that the implementation of LookupCube has changed. There is no additional information.

I don't use LookupCube any more I use multiple measure groups, possibly linking them in if they are shared across more than one cube.

Sunday, February 19, 2012

How to get Extended error information from stored procedure

Hi

I have a stored procedure in SQL server 2005. It works fine when I execute it from the Management Studio.
But when executing it from ASP.NET code like this:

.... Of course more code is executed before this call ....
int retVal =this.odbcCreateDataBaseCommand.ExecuteNonQuery();

retVal is -1. But -1 doesn't really tell me what the problem is?

Is there anyway to get extended error information so I can figure out whats going wrong?

(The stored procedure was working fine in SQL server 2000 before I upgraded to SQL server 2005. I use .NET Framework 1.1 and ODBC Sql Native Client to access the 2005 server.)

Regards

Tomas

My own thought...
Maybe .NET Framework 1.1 and SQL Server 2005 and ODBC SQL Native Client have poor compatibility...

Anyone out there with experience/insight?

Thanks
Tomas