Showing posts with label access. Show all posts
Showing posts with label access. Show all posts

Monday, March 26, 2012

Grouping common functionality in multiple stored procedures

Hi i have always used views in my code to group common functionality in my sql expressions and then i can simply call these views in my data access layer by saing:

SqlCommand cmd = new SqlCommand("SELECT * FROM vw_Documents WHERE CategoryID = @.CategoryID", cn);

However my view has become so complicated that i had to convert it to a stored procedure called sp_Documents. The problem now though is that is that i wish to do queries against the data returned but i can't simply say:

SqlCommand cmd = new SqlCommand("SELECT * FROM sp_Documents WHERE CategoryID = @.CategoryID", cn);

The only way i can see to do it is to create a stored procedure for every single senario i have passing in the appropriate values as parameters. This seems a pretty messy solution to me because i would have repeated logic in all my stored procedures. Therefore i was wondering if there's a simpler way for me to do this or am i just being lazy :).

Appreciate if someone could help,

Oops i found the solution straight after i posted. User defined functions. Never realized you could return more than one value with a function in sql server. If there is a better solution please let me know but this seems to tick all the boxes.

Edit: I have discovered that this is not going to work for me since my stored procedure produces different columns (based on values passed in) and it appears that the Multi-statement Table-Value User-Defined Function requires you to specify the structure you will be outputting.

|||

>SqlCommand cmd = new SqlCommand("SELECT * FROM vw_Documents WHERE CategoryID = @.CategoryID", cn);

It is preferable to select just the columns you require.

>However my view has become so complicated that i had to convert itto a stored procedure called sp_Documents.
>The problem now though isthat is that i wish to do queries against the data returned but I can'tsimply say:
>SqlCommand cmd = new SqlCommand("SELECT * FROM sp_Documents WHERE CategoryID = @.CategoryID", cn);
>The only way i can see to do it is to create a stored procedure forevery single scenario i have passing in the appropriate values asparameters
It is tempting to code complicated IF ... SELECT ... ELSE SELECT ..., however it is generally best to a code one stored procedure for each permutation as then the query engine can optimise each variation. There are some situations where serial scanning of a table is an acceptable perfomance hit and it is possible to use the COALESCE trick to search any combination of 1 to N columns for specific value. For example if table FRED has non-null columns A through D and the sp has args &A to &D and for simplicity the allowed values are non-zero integer then:
IF &A = 0 SET &A = NULL
IF &B = 0 SET &B = NULL
IF &C = 0 SET &C = NULL
IF &D = 0 SET &D = NULL
SELECT A, B, C, D FROM FRED
WHERE COALESCE(&A, A) = A
AND COALESCE(&B, B) = B AND COALESCE(&C, C) = C AND COALESCE(&D, D) = D

If say &A is the only non-zero parameter then the effect select simplifies to SELECT A, B, C, D FROM FRED WHERE &A = A, as COALESCE selects the first non-null value.

sql

Grouping by Page Count in CR 8.5

Datasource: Access 2000
CrystalReports: 8.5
Language: Visual Basic 6

I wonder if someone can help with this.

I am have a report that collates customer details and it is currently grouped on customer number.

These details are used to generate mail shots and it is now a requirement that the report is ordered by page count.

Is there a way that the total number of pages printed for each customer number can be used to sort the report.

So far the formulas I have tried cannot be completed because the report needs to generated first so the page numbers can be calculated.

The solution can be either in code or in the report but if in the report I need to be able to obtain the page totals for each customer number into code.

Many thanks in advance.Do you want to know how many pages does Report have for each Customer?sql

Wednesday, March 21, 2012

Group-based authorization in Forms Authentication

Hi,
I am using the Forms Authentication Sample to authenticate users in RS. I am
trying to find a sample code to check setup groups and assign access on
Folders to groups instead of users.
Please help.
Cheers
SaiSearch the below URL for 'forms authentication groups'. I found quite a few
results:
http://groups-beta.google.com/group/microsoft.public.sqlserver.reportingsvcs
--
Adrian M.
MCP
"Sai Vootla" <Sai@.discussions.microsoft.com> wrote in message
news:86332D5C-5A49-4F29-9ED0-B2ABBEDFBF6E@.microsoft.com...
> Hi,
> I am using the Forms Authentication Sample to authenticate users in RS. I
> am
> trying to find a sample code to check setup groups and assign access on
> Folders to groups instead of users.
> Please help.
> Cheers
> Saisql

Friday, February 24, 2012

Group Access Problem

Hi here
After I installed reporting service on Windows 2000 server and upgrade
sp1, I got group access problem. For example, I grant one active directory
group (server name\group name ) as browser of a folder. But the user in this
group can't access the folder, get the permission error.
Anything I can resolve this problem. Because I don't want to add one by
one single user to access the report.
Thanks in advance
TracyI think some security info is cached. Does it work later, or after
restarting? This should not have changed in SP1.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"tracy" <trlu@.vsb.bc.ca> wrote in message
news:ee2mECWXEHA.808@.tk2msftngp13.phx.gbl...
> Hi here
> After I installed reporting service on Windows 2000 server and upgrade
> sp1, I got group access problem. For example, I grant one active
directory
> group (server name\group name ) as browser of a folder. But the user in
this
> group can't access the folder, get the permission error.
> Anything I can resolve this problem. Because I don't want to add one by
> one single user to access the report.
> Thanks in advance
> Tracy
>|||Hi Jason,
Finially we found out because that group is a distribute group instead
of a security group, that's the reason the user under the group doesn't have
the access to view the folder.
Thanks
Tracy
"Jason Carlson [MSFT]" <jasoncar@.microsoft.com> wrote in message
news:%23jQ0%23hZXEHA.4000@.TK2MSFTNGP09.phx.gbl...
> I think some security info is cached. Does it work later, or after
> restarting? This should not have changed in SP1.
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
> "tracy" <trlu@.vsb.bc.ca> wrote in message
> news:ee2mECWXEHA.808@.tk2msftngp13.phx.gbl...
> > Hi here
> > After I installed reporting service on Windows 2000 server and
upgrade
> > sp1, I got group access problem. For example, I grant one active
> directory
> > group (server name\group name ) as browser of a folder. But the user in
> this
> > group can't access the folder, get the permission error.
> > Anything I can resolve this problem. Because I don't want to add one
by
> > one single user to access the report.
> >
> > Thanks in advance
> >
> > Tracy
> >
> >
>

Group Access

Hi all
Is there a way to create a script of a database user to see all of the
objects that user has access to and what the access is for each object?
Thanks
Kevin
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
Hi
You may want to look at the sysprotects table or possibly the
INFORMATION_SCHEMA.TABLE_PRIVILEGES view
John
"Kevin Hayward" wrote:

> Hi all
> Is there a way to create a script of a database user to see all of the
> objects that user has access to and what the access is for each object?
> Thanks
> Kevin
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!
>

Sunday, February 19, 2012

Group Access

Hi all
Is there a way to create a script of a database user to see all of the
objects that user has access to and what the access is for each object?
Thanks
Kevin
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!Hi
You may want to look at the sysprotects table or possibly the
INFORMATION_SCHEMA.TABLE_PRIVILEGES view
John
"Kevin Hayward" wrote:

> Hi all
> Is there a way to create a script of a database user to see all of the
> objects that user has access to and what the access is for each object?
> Thanks
> Kevin
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!
>

Group Access

Hi all
Is there a way to create a script of a database user to see all of the
objects that user has access to and what the access is for each object?
Thanks
Kevin
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Hi
You may want to look at the sysprotects table or possibly the
INFORMATION_SCHEMA.TABLE_PRIVILEGES view
John
"Kevin Hayward" wrote:
> Hi all
> Is there a way to create a script of a database user to see all of the
> objects that user has access to and what the access is for each object?
> Thanks
> Kevin
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
>

gridview binding with sqlConnection objects...

Hello All, I am new to data access and

i have got the problem to display the data into the page by binding the gridview with sqlConnection, sqlCommand and sqlDataReader objects. The actually code is written as:

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!Page.IsPostBack)

{

SqlConnection myConnection;

SqlCommand myCommand;

SqlDataReader myReader;

myConnection =newSqlConnection();

myConnection.ConnectionString =ConfigurationManager.ConnectionStrings["LatteConnectionString"].ConnectionString;

myCommand =newSqlCommand();

myCommand.CommandText ="select * from AntiVirusVendors";myCommand.CommandType =CommandType.Text;

myCommand.Connection = myConnection;

myCommand.Connection.Open();

myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

GridView1.DataSource = myReader;

GridView1.DataBind();

myCommand.Dispose();

myConnection.Dispose();

}

}

and the GridView in html is listed as:

<div>

<asp:GridViewID="GridView1"runat="server">

</asp:GridView>

</div>

So the problem is --> there is nothing shown in the page, no errors no anything... just the empty page.

Any ideas would be appreciated. Thanks in advance!

Joe

sorry, the problem has been solved.

Gridview & SQL data source

I have a few Stored procedures that return values, some need parameters passing and others don't.

Up to now to access that data in a Web App I have called this procedure using VB after seting up a data block etc.

However I notice that the Web Developer express edition has some tools that look like they should help. I have used the in-built tools to create a SQL data source linked to a details view. I then specified that this should connect to my database (sql2005 hosted) and then specified Custom SQL or Stored procedure.

From the drop down I can then select the SP that purely returns values. When I try to test this query I get an error to say that the query did not return any data tables.

Is there a way to get values returned from a SP in this way?

Regards

Clive

You can use events like (Updating, Updated, Selecting, Selected etc) to do your cutomization. For example, if your method returns an output parameter then:

Sub OnDSUpdatedHandler(ByVal sourceAs Object,ByVal eAs SqlDataSourceStatusEventArgs)If e.AffectedRows > 0Then' Perform any additional processing, such as setting a status label. Label1.Text = Request.LogonUserIdentity.Name & _" changed user information sucessfully!" dim outputvalue asString outputvalue = e.Command.Parameters("yourparamname").Value.ToString()Else Label1.Text ="No data updated!"End If End Sub'OnDSUpdatedHandler

As you can see, I haven't done any kind of error checking. Please ensure that your code does. If you need more help, reply to the post explaining the problem.

|||

I think my problem is earlier than this stage to be honest.

For instance I have a SQL 2005 Stored Procedure that returns values from a table I can run this in SQL server itself and it works fine.

When definign this SP as a datasource using the detailsview object in Visual Web Developer I get the error I mentioend above when runnign the test option while I am stil in the wizard. So it looks liek some problem with callign the SP, yet it works OK natively.

|||

DetailsView, FormView, Gridview etc controls are designed to show a record/records. So, if you are using a SqlDataSource that just returns a single value, you cannot bind that to abovementioned controls. Can you explain why do you need to have a Detailsview that shows only single value?

Whenever asking a question, please add as much info as possible. Otherwise, we have to guess other parts (as you can see from my previous post) which is obviously not what you are looking for. Provide more info about your problem/scenario.

|||

I have a stored procedure that takes no paramteres but returns some values which are calculated from a number of tables to returns some summary results. if I execute the SP from SQL manager I get 5 values returned which appear as output parameters.

I was hoping to be able to link these quickly and easily into a web page using a SQL data source linking to this SP as it's datasource.

I was hoping that the details view would then display the values returned.

There maybe an easier or better way to do this. I am a beginner with all this, and wanted to explore how to use a stored procedure as a datasource.

Regards

Clive

|||

If the stored procedure returns resultset (table with columns and rows) then it would show nicely in the DetailsView, GridView etc. I don't think these controls have builtin ability to look for output parameters and bind those values. I think you should do this programmatically.

Connect to db, run the storedproc, get the results. Then you can either manually populate the values in controls or you can create a collection of values and bind it to a dataaware control. If you need sample code, then reply to the post mentioning your preference.