Pages

Search This Blog

Tuesday, April 15, 2008

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Try to upload picture and hit below error.




A generic error occurred in GDI+.

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.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 469: MemoryStream mem = new MemoryStream();
Line 470: resizedImage.Save(mem, jpegICI, encoderParams);
Line 471: resizedImage.Save(filePath + "\\" + fileName, ImageFormat.Jpeg);
Line 472:

Source File: c:\Inetpub\wwwroot\BlogA\Account.aspx.cs Line: 471

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +397778
System.Drawing.Image.Save(String filename, ImageFormat format) +69
Account.WarpImageDimensions(String filePath, String fileName, Bitmap imageToSave) in c:\Inetpub\wwwroot\BlogarateNewLayout\Account.aspx.cs:471
Account.ImageButton1_Click(Object sender, ImageClickEventArgs e) in c:\Inetpub\wwwroot\BlogA\Account.aspx.cs:392
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

in my case:

It's caused by 2 thing:
1. Upload path - i put the wrong path
2. Folder permission - set the correct permission. In my case, i allow write permission for internet user (IUSR_xxxxx).

Problem solved.

Manage/Delete IIS log files using scheduler

Microsoft have provide a very good resource kits. Forfiles is one the them that we can use to manage our log files especially IIS log. My purpose for this article is to show how i use forfiles to help me to manage/delete my IIS log file more than 14 days (you can delete any time frame you want).

Steps:
1. download and install Windows Server 2003 Resource Kit Tools
2. write a bat script
3. create a scheduler


Let look at the details

1. download and install Windows Server 2003 Resource Kit Tools

In order to us it, you need to install it in your server first. Go to microsoft website "Windows Server 2003 Resource Kit Tools" and download it. After finish downloading, you can start to install it.
After finish installation, you can find Forfiles in C:\WINDOWS\system32\forfiles.exe


2. write a bat script

Syntax for forfiles

forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d[{+ -}] [{MM/DD/YYYY DD}]]

the details syntax you can get it from technet.

For me, i want to delete the log files date 14 days before. Below are some of the details
  1. log file location = C:\WINDOWS\system32\LogFiles\W3SVC1
  2. file type = *.log
  3. Date to delete = -d -14 (14 days before)

Below is the command that i'm able to come out and save it as .bat format. Say, "managelog.bat"

Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c "Cmd /C DEL @File"

copy forfiles.exe from C:\WINDOWS\system32\forfiles.exe and managelog.bat to the same location which you prefer.

3. create a scheduler

You need to create a scheduler to run the job automatically. For me, i run my job weekly at mid night 12:30AM.

To know how to create a window scheduler job, please find reference here.

Please test it before make it run automatically. I suggest that you use below command line to test. I change the DEL to ECHO so that i work safely.

Forfiles -p C:\WINDOWS\system32\LogFiles\W3SVC1 -s -m *.log -d -14 -c "Cmd /C ECHO @File"

Done. Good luck.

Sunday, April 13, 2008

Shrink Database MSSQL

Log file grow until very huge file? Check this step to shrink sql ldf file http://dotnetfish.blogspot.com/2007/12/shrinking-transaction-log.html

Thursday, April 10, 2008

Forbidden: Execute access is denied

The page cannot be displayed





You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.



Please try the following:



  • Contact the Web site administrator if you believe this directory should allow execute access.


HTTP Error 403.1 - Forbidden: Execute access is denied.


Internet Information Services (IIS)



During the application setting up, i miss out one step. That is Executive Permissions. To solve the problem, Select "Scripts Only" or "Scripts and Executables" under Executive Permissions option. Problem solved.


CS0101: The namespace '<global namespace>' already contains a definition for 'xxxxx'

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

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0101: The namespace '<global namespace>' already contains a definition for 'xxxx'




check whether you have a copy of the file with different name but using the same class (duplicate file). In My case, i have a backup copy for a aspx file. Delete the file or exclude from the project will solve the problem.

Thursday, April 3, 2008

Change Table and Stored Procedure Ownership From xxx to DBO

Need to change the ownership for table and stored procedure

Script for change table ownership

DECLARE @old sysname, @new sysname, @sql varchar(1000)

SET @old = 'oldOwner'
SET @new = 'dbo'
SET @sql = ' IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES
WHERE
QUOTENAME(TABLE_SCHEMA)+''.''+QUOTENAME(TABLE_NAME) = ''?''
AND TABLE_SCHEMA = ''' + @old + ''' )
EXECUTE sp_changeobjectowner ''?'', ''' + @new + ''''

EXECUTE sp_MSforeachtable @sql


Credit should give to Scott Forsyth

change ownership for stored procedure

DECLARE
@OldOwner sysname,
@NewOwner sysname

SET @OldOwner = 'oldOwner'
SET @NewOwner = 'dbo'

DECLARE CURS CURSOR FOR
SELECT
name
FROM sysobjects
WHERE type = 'p'
AND
uid = (SELECT uid FROM sysusers WHERE name = @OldOwner)
AND
NOT name LIKE 'dt%' FOR READ ONLY

DECLARE @ProcName sysname
OPEN CURS
FETCH CURS INTO @ProcName
WHILE @@FETCH_STATUS = 0
BEGIN
IF @@VERSION >= 'Microsoft SQL Server 2005'
BEGIN
EXEC('alter schema ' + @NewOwner + ' transfer ' + @OldOwner + '.' + @ProcName)
exec('alter authorization on ' + @NewOwner + '.' + @ProcName + ' to schema owner')
END
ELSE
EXEC('sp_changeobjectowner ''' + @OldOwner + '.' + @ProcName + ''', ''' + @NewOwner + '''')

FETCH CURS INTO @ProcName
END

CLOSE CURS
DEALLOCATE CURS

Credit should give to Greg Duffield









Tuesday, April 1, 2008

Ping an IP through a specific port in cmd prompt or telnet

Well, sometimes we need to know whether the port in open or block, we need to do some checking or troubleshoot through ping/telnet. We cannot ping a IP with port but we can telnet certain IP together with Port no.

For example:
Go to open command prompt, if we want to check whether port 21 is working for IP 203.166.87.9 what we need to do is
> telnet 203.166.87.9 21

please tell me it's work. thanks

Sunday, March 16, 2008

Visual Studio .NET has detected that the specified Web Server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web applications o

I've received error message when try to open visual studio.net.
Visual Studio .NET has detected that the specified Web server is not running ASP.NET version 1.1. You will be unable to run ASP.NET Web applications or services

I suspect some of my newly installed application cause the webserver port change from 80 to others. My case is easy to solve, i uninstall my newly install app called: "Raysource" and it's work and running.

For more information on this error, please check in

http://support.microsoft.com/kb/817267

http://www.dotnetspider.com/kb/Article2476.aspx





Sunday, March 9, 2008

Exclusive access could not be obtained because the database is in use.

I try to restore a new database in MSSQL 2005 and hit error
Restore Failed For Server 'xxxx' (Microsoft.SqlServer.Smo)
Additional information:
System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)


This is mostly caused by others user/session is using the database at the same time. To check whether got others user accessing the same database, execute SP_WHO will show who is using the database. Execute KILL to kill the process. In my case, i want to kill process with spid = 53

execute SP_WHO -- See which process in running

Execute KILL 53 -- 53 is the process id spid that i want to kill before restore.

In my case, i restore the database using script instead of using the SSMS.

Below is the script that i use to restore without any issue.


RESTORE DATABASE RateMyPosts
FROM DISK = 'C:\Documents and Settings\DEV1\Desktop\RatePosts.bak' WITH REPLACE,
MOVE 'RatePosts' TO
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\RatePosts.mdf',
MOVE 'RatePosts_Log' TO
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\RatePosts_log.ldf'

Saturday, March 1, 2008

VBScript: disabled and enabled button

<html>
<head>
<title>VBScript Example: disabled and enabled button</title>
<SCRIPT Language="VBScript">
sub enableButton()
if frm.chkbox_1.checked = true then
frm.btn_1.disabled = false
else
frm.btn_1.disabled = true
end if

end sub
</SCRIPT>
</head>
<body>
<form name=frm>

<input type="checkbox" name="chkbox_1" value="ON" onclick="enableButton()"></input>
<input type="submit" value="I Agree" name="btn_1" disabled></input>

</form>
</body>
</html>