Showing posts with label correctly. Show all posts
Showing posts with label correctly. Show all posts

Friday, March 9, 2012

Declarative SQL problem

I can't figure out what is wrong with the code below.

The first line prints out correctly when I am logged in

If I substitute the actual username in the SQL, the Repeater works fine, printing out the item from the db.
But using
WHERE USERNAME='<%= User.Identity.Name%>'
in the SelectCommand returns no rows.

Can anyone help?

Thanks,

Michael

<h3>News for <%=User.Identity.Name%></h3>

<asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ ConnectionStrings:NEWWEB %>"ProviderName="<%$ ConnectionStrings:NEWWEB.ProviderName %>"SelectCommand="SELECT USERNAME FROM ASPNET_MEMBERSHIP WHERE USERNAME='<%= User.Identity.Name%>' "></asp:SqlDataSource><asp:RepeaterID="FirmAlertsRepeater"runat="server"DataSourceID="SqlDataSource2">

<ItemTemplate><b><%# DataBinder.Eval(Container.DataItem, "USERNAME")%></b>—<br/> </ItemTemplate>

</asp:Repeater>

YOu should use an expression for username. I wrote a blog post on how to do that here. Basically, you need to an expression builder to your app_code directory. It's very straight forward.

http://peterkellner.net/2006/09/18/expressionbuilderidentity/

HTH's.

|||

Interesting way of handling it, however, this is what I do:

Inside global.aspx.vb, add:

Protected

Sub Application_PreRequestHandlerExecute(ByVal senderAsObject,ByVal eAs System.EventArgs)If User.Identity.IsAuthenticatedAndAlso Context.SessionIsNotNothingAndAlso Session("Username")IsNothingThen

Session("Username")=user.Identity.Name

end if

end sub

Then just create a session parameter using the Username session property for your SqlDatasource.

|||

Hello Peter,

Thanks, I tried that and it works.

But I am at a loss as to why that is neccessary. Can you point me to anything that explains why the variable can't be used as is?

Michael

|||It's a databinding issue. <%#, that is expression generate code at runtime that has to be executed as an event. Expression are done at compile time so the code is their already. HTH's.|||

There are many reasons why.

First you used ASP syntax to try and insert a value into a server control property. That won't work because the server control property is initialized long before your expression is evaluated.

You COULD use a databinding syntax <%# %> instead, however, the server control must support databinding, and the property you are databinding must support being databound.

Lastly, if you were going to use databinding (assuming the SqlDatasource's SelectCommand property was databindable, which it isn't), you must surround the attribute with single quotes, not double quotes or the databinding expression won't work.

|||

Thanks Peter and Motley,

So much to learn.

So there is no general Eval function that asp.net uses to make sure the variable is resolved before compiling? We have to build our own?

Michael

|||

I tried Peter's method first. It worked very nicely.

But since I am a contractor, and someone else will have to try to understand it later, I switched over to Motley's method - re-done in C#:

In the declarative code:

<

SelectParameters><asp:SessionParameterName="USERNAME"SessionField="USERNAME"DefaultValue=""/></SelectParameters>

In the cs:

protected

void Page_PreInit(object sender,EventArgs e)

{

string strUsername = HttpContext.Current.User.Identity.Name;

Session[

"username"] = strUsername;

}

Wednesday, March 7, 2012

Decimal not displaying correctly from Excel

I have an Excel spreadsheet with three columns of data, one of which is a "Score". The score will range between 1.0 and 0, going out to two decimal places. I am able to get this data into a global temporary table. I have a script in which a message box pops up, displaying the MIN value of the "Score" field in the temp table. The MIN value is .2. When I try to get the data from the temp table to a staging table, the Scores are all rounded to the nearest whole number. I think I've tried using every numeric data type for the staging table, and I always get the same results. In the temp table, Score is defined as such:

[Score] [decimal](18, 0) NULL

Does anybody know what I need to do to get the score to display acccurately?

Lindsay

Make Score a decimal (18,2)

The "2" refers to the number of decimal places after the decimal point.

(actually you could get away with much less than 18.)

Dylan.

|||

I'm sorry, Score is defined in the temp table as 18,5 not 18,0.

I also changed Score in the staging table to 18,5 as opposed to Float, but I'm still getting the same results.

|||I found the problem. I was changing a different column using Derived Column Transformation, and the Score field was also in there, converting it to a string. Deleted it, and now I'm back in business Thank you for forcing me to look harderSmile|||

Sometimes I find that if I ask the question, I end up finding the solution.

Something about framing the question forces you to really think about the solution.

Please mark the thread as Answered, though!

Dylan.

Saturday, February 25, 2012

Debugging while running reporting services

I am attempting to debug a customer security dll that is called by Reporting Services. The DLL works great and functions correctly. I am trying to set breakpoints in the code, but they are ignored. I changed the web.config for ReportManager and ReportServer to set debug=true. However, still no luck. The application never stops, it just works.

I have tried this on a Windows XP Pro with no luck. Any suggestions?

Are you debugging the asp.net worker process? Did you configure VS to point to the correct symbols?

-Daniel

Friday, February 24, 2012

Debugging SQL Server 2005 Stored Proc with Visual Studio 2005

Hello,

we have a SQL server 2005 with Visual studio Prof. 2005 in the

employment.

The debuggers function only in Visual studio correctly, as long as no

code on the SQL server must be implemented.

If a BREAK POINT in a Stored Procedure is set, this is not activated,

since this cannot be bound.

Does someone know, what it lies and can like one it eliminate?

Thank you for your assistance in advance.

Yours sincerely

Big_Ben_31


This entry was translated automatically with the translation

service babel.altavista.com from the German into English.

I will have to ask the obvious question about your setup. Have you ensured that it is complete? The new topics in BOL and MSDN describe the steps in details including troubleshooting ones. Please start with the links below:

http://msdn2.microsoft.com/en-us/library/kkyhd4yb.aspx

http://msdn2.microsoft.com/en-us/library/s4sszxst.aspx