Friday, November 19, 2010

Add JavaScript to handle two scripts in ASP.NET

protected void ApplyJavaScriptForPostToIris()


{

System.Text.StringBuilder sbValid = new System.Text.StringBuilder();

sbValid.Append("if (confirm('Are you sure you want to post this file to app') == true){");

sbValid.Append("this.disabled = true;");



sbValid.Append("} else { return false;}");

sbValid.Append(this.ClientScript.GetPostBackEventReference(this.btnPostToIRIS, "") + ";");



this.btnPostToIRIS.Attributes.Add("onclick", sbValid.ToString());

}

Tuesday, November 09, 2010

Looping through SQL Server ... This has to be saved. To many hours spent.

I know I will have to do this again....

This article describes various methods that you can use to simulate a cursor-like FETCH-NEXT logic in a stored procedure, trigger, or Transact-SQL batch.


Use Transact-SQL Statements to Iterate Through a Result Set

There are three methods you can use to iterate through a result set by using Transact-SQL statements.



One method is the use of temp tables. With this method, you create a "snapshot" of the initial SELECT statement and use it as a basis for "cursoring." For example:

/********** example 1 **********/



declare @au_id char( 11 )



set rowcount 0

select * into #mytemp from authors



set rowcount 1



select @au_id = au_id from #mytemp



while @@rowcount <> 0

begin

set rowcount 0

select * from #mytemp where au_id = @au_id

delete #mytemp where au_id = @au_id



set rowcount 1

select @au_id = au_id from #mytemp

end

set rowcount 0







A second method is to use the min function to "walk" a table one row at a time. This method catches new rows that were added after the stored procedure begins execution, provided that the new row has a unique identifier greater than the current row that is being processed in the query. For example:

/********** example 2 **********/



declare @au_id char( 11 )



select @au_id = min( au_id ) from authors



while @au_id is not null

begin

select * from authors where au_id = @au_id

select @au_id = min( au_id ) from authors where au_id > @au_id

end





NOTE: Both example 1 and 2 assume that a unique identifier exists for each row in the source table. In some cases, no unique identifier may exist. If that is the case, you can modify the temp table method to use a newly created key column. For example:

/********** example 3 **********/



set rowcount 0

select NULL mykey, * into #mytemp from authors



set rowcount 1

update #mytemp set mykey = 1



while @@rowcount > 0

begin

set rowcount 0

select * from #mytemp where mykey = 1

delete #mytemp where mykey = 1

set rowcount 1

update #mytemp set mykey = 1

end

set rowcount 0











-- ================================================


-- Template generated from Template Explorer using:

-- Create Procedure (New Menu).SQL

--

-- Use the Specify Values for Template Parameters

-- command (Ctrl-Shift-M) to fill in the parameter

-- values below.

--

-- This block of comments will not be included in

-- the definition of the procedure.

-- ================================================

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author: Robert Dannelly

-- Create date: 11/09/2010

-- Description: Resubmission Validation

-- =============================================

CREATE PROCEDURE ResubmissionValidation

-- Add the parameters for the stored procedure here

@ImportID int

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;



-- Insert statements for procedure here

DECLARE @ResubmissionTest TABLE

(

[ImportMetricID] [int] NULL,

[ImportID] [int] NULL,

[MetricInstanceID] [int] NULL,

[MetricValue] [varchar](100) NULL,

[NDTR] [varchar](20) NULL,

[MetricValueDate] [datetime] NULL,

[Narrative] [varchar](300) NULL,

[Resubmission] [varchar](50) NULL,

[ImportMetricStatus] [varchar](50) NULL,

[ImportFailureMsg] [varchar](200) NULL,

[CurrentMetricValue] [varchar](50) NULL

)



INSERT INTO @ResubmissionTest (ImportMetricID, ImportID, MetricInstanceID, MetricValue, NDTR, MetricValueDate, Narrative,

Resubmission, ImportMetricStatus, ImportFailureMsg, CurrentMetricValue)

SELECT ImportMetricID, ImportID, MetricInstanceID, MetricValue, NDTR, MetricValueDate, Narrative,

Resubmission, ImportMetricStatus, ImportFailureMsg, CurrentMetricValue FROM tblImportMetric WHERE ImportID = @ImportID --Need to change to Variable



-- This is used for Testing RBD

--SELECT * FROM @ResubmissionTest





DECLARE @ImportMetric_ID char(11), @Resubmission varchar(10)



SELECT @ImportMetric_ID = min(ImportMetricID) FROM @ResubmissionTest





--Begin LOOP

WHILE @ImportMetric_ID is not null

BEGIN

DECLARE @MetricInstanceID int,

@MetricValueDate DateTime



SELECT @MetricInstanceID MetricInstanceID FROM @ResubmissionTest WHERE ImportMetricID = @ImportMetric_ID



SELECT @MetricValueDate MetricValueDate FROM @ResubmissionTest WHERE ImportMetricID = @ImportMetric_ID

-- Be sure to change the values to @MetricInstanceID AND @MetricValueDate

EXECUTE ImportCheckResubmission @MetricInstanceID, @MetricValueDate, @Resubmission OUTPUT



IF @Resubmission = 'Yes'

BEGIN

UPDATE @ResubmissionTest

SET ImportFailureMsg = 'There is an existing value for this metric and interval. Please indicate if it is a resubmission.'

WHERE ImportMetricID = @ImportMetric_ID





SELECT @ImportMetric_ID = min(ImportMetricID) FROM @ResubmissionTest WHERE ImportMetricID > @ImportMetric_ID

END

END



DELETE FROM tblImportMetric WHERE ImportID = @ImportID



INSERT INTO tblImportMetric (ImportID, MetricInstanceID, MetricValue, NDTR, MetricValueDate, Narrative,

Resubmission, ImportMetricStatus, ImportFailureMsg, CurrentMetricValue)

SELECT ImportID, MetricInstanceID, MetricValue, NDTR, MetricValueDate, Narrative,

Resubmission, ImportMetricStatus, ImportFailureMsg, CurrentMetricValue FROM @ResubmissionTest WHERE ImportID = @ImportID --Need to change to Variable





--This is used for Testing

--SELECT * FROM tblImportMetric

END

GO

Thursday, November 04, 2010

Demystify SQL Debugging with with Visual Studio

Here is what I did to fix this issue "FINALLY"

http://www.asp.net/data-access/tutorials/debugging-stored-procedures-vb
#1 Connect using Windows Authentication as the same account on the local machine that must have sysadmin rights in the Instance of SQL Server.
#2 They use Server Explorer and connect with that same account and then once connect right click on the DB and check "Application Debuggin. I am posting this to my blog.
Great posts. By the way I feel the pain of remote individuals, my answer tell you management that if you want fast, rapid code to fork up the dough for SQL Developer Edition and do all you coding locally with a quality source control.



Robert.

GridView

HTML:

Tuesday, October 19, 2010

Add Using for Controls or lookup very useful

In VS 2008, when the caret is on the name of the class which doesnt have a using statement in the file, SHIFT+ALT+F10 will bring up a context menu to add the using statement.

Reboot Remotely

When you work in distributed environment you probably use remote desktop session as you primary method of sql server machines administration. When critical windows updates are installed or when you install system or sql server service pack installation wizard promts you to restart the box in order to complete the installation. And it happens from time to time that this  machine hangs on reboot process for some reason and you can no longer connect it via remote desktop. If it was you local computer you could enter into your server room and press the reset button but if it stand thousands miles away from you it becomes a real problem.
How to restart or shutdown remote machine
If you can ping this machine from other computer and you have administrators rights on that machine you may use windows utility.
On a computer that has connection to the server which needs to be restarted or shutdown go to Start -> Run and type shutdown -i

This window will show up. Press Add and type either IP or DNS of remote server.
Select shutdown or restart and press OK. That 's it. For your convenience you may run from command line constanct ping  (ping servername -t) when the server actually stopped to respond to pings and when it started again.
Alternatively you can go to command prompt (start -> run -> cmd) on your workstation and Typeshutdown -r -m \\x.x.x.x
Replace x.x.x.x with the IP address or computer name of the remote machine. -r option is for restart, don't use -r if want to just shut down the system.  

Thursday, August 05, 2010

SharePoint Site Collection Administration

Lesson learned. If you are ever asked to maintain a SharePoint site the first thing to do is say, "Grant me Site Collection Admin Rights". Why? Because if you are testing security and you do not know who the Site Collection Admin are then if you remove security the individuals in that role will still have access. (Nice 2 hour lesson learned)

Thursday, June 17, 2010

AJAX Install

If you develop ASP.NET applications with AJAX here is a step by step guide so you do not bang your head.

1) Download the latest version from CodePlex for AJAX.
2) Extract to a location of your choice
3) Add the AjaxControlToolkit.dll & AjaxControlToolkit.pdb to you Web layer project /bin folder
4) Create a new Tab in your Toolbox and point to the new AjaxControlToolkit.dll
5) Create a reference to your AjaxControlToolkit.dll
6) Finally ensure the line in your Web.config is that same version as your dll assembly - (Simply right click the dll and look at the properties for assembly info.

Friday, April 16, 2010

Visual Studio 2010

Microsoft has released Microsoft Visual Studio 2010. I think it is time for me to upgrade to Windows 7 and start using there new tool set in order to keep up with the times.

SharePoint and SQL Sever Reporting Integration

Well, I must tell you that I had to reach out to Microsoft yesterday and use 1 of my support calls with my MSDN Subscriptions. I have been tasked with integrated SQL Server Reporting Services with MOSS 2007.

This will be the first implmentation at my company and I very excited to have a fantastic presentation for my upper managment.

A lot of work has been put into this and I plan to sell this great feature.

Thursday, April 01, 2010

New Trick Envrionment Variables

public static string SecurePath = Environment.GetEnvironmentVariable("SECURED_APP_PATH");

You can right click on your computer > Advanced Tab > set the variables. Warning they will not take effect till a reboot.

This would not worth using for a hosted appllication when you do not have access to the server.

Monday, March 08, 2010

Time to build the app

I am ready to build the app for retirement. 1 to 2 hours a day.

Define - 20 more hours
- Design DB (Completed)
- Design Workflow (Completed)
- Design UI(s) All screens (Completed)
- Design Objects (Completed)
Measure - 10 hours (2-6 Months, but will be done before I am 40 :-) )
Analyze - 40 hours (Done)
Improve (Build) - (In Process)
- Database Development (8 Hours Completed)
- Application (Web to start in Progress 2-6 months
* Web UI
* Business Layer
* Data Layer (Completed)
* Test Test Test fix fix fix test test test
* Demo to friends and family (Huge Milestone - break out Beer and Wine)

Control - Will know after Improve Phase)

Friday, February 19, 2010

Trace.axd

One thing I am going to remember is Trace with ASP.NET... It is so powerfull to watch Application, Session and ViewState.

<trace enabled="true" requestLimit="40" localOnly="false" />

Very important when troubleshooting:

http://msdn.microsoft.com/en-us/library/y13fw6we%28VS.71%29.aspx

Thursday, February 04, 2010

Kill Task in XP

c:\>taskkill /pid 3252 /F

Force kill aspnetwp.exe....

Than stop the IIS and then delete temporary files.

Monday, January 11, 2010

Ctrl-Alt-Del on remote desktop aka server

In order to send Ctrl-Alt-Del keystrokes to remote computer connected via Remote Desktop client, just press the following workaround keyboard shortcuts specially used in Remote Desktop environment:

Ctrl+Alt+End