Monday, December 27, 2010
SharePoint service uses all available CPU (owstimer.exe)
To eliminate the CPU utilization problem, in services.msc, I stopped and disabled the Windows SharePoint Services Timer service.
To determine when SharePoint was installed, I launched SQL Server Management Studio on the test server and connected to the SQL Server instance on the local machine. There I found some SharePoint databases -- WSS_AdminContent, WSS_AdminConfig and WSS_Content. By right-clicking each of these and viewing the properties, I was able to see that they were created on Dec 30 2009, almost a year ago. SharePoint has apparently been present all along, and was likely installed as part of Team Foundation Services.
This doesn’t explain why a SharePoint service suddenly started performing some action that consumed all available CPU time. That remains a mystery. According to several other online posts, other people have experienced the same thing.
Friday, December 17, 2010
Missing DLL causes error "file has not been pre-compiled, and cannot be requested"
The file '/step1.aspx' has not been pre-compiled, and cannot be requested.
The filename step1.aspx would be replaced with the name of whatever page I was trying to view.
I eventually determined that the error message didn't mean at all what it said. What it really meant was that Telerik.Web.UI.dll was missing from the website's bin folder. The Telerik control was referenced in a master page that was used by most pages of the site, and therefore the error occurred on almost every page.
Simply adding the missing DLL to the bin folder resolved the problem. I then got to wondering why the DLL was missing in the first place. Here's the answer.
I installed Telerik RadControls for ASP.NET AJAX using the MSI installer provided by Telerik. Among other things, this installed Telerik.Web.UI.dll to C:\Program Files (x86)\Telerik\RadControls for ASP.NET AJAX Q1 2010\Bin20.
I copied Telerik.Web.UI.dll from there to a folder named Shared Assemblies in my .NET solution. I use this folder to store some third-party DLLs to which one or more of my projects make references.
In my project, I added a reference by browsing to the copy of Telerik.Web.UI.dll in my Shared Assemblies folder. Nonetheless, Visual Studio added the reference from the GAC, and did not copy the DLL to my project's bin folder. Because my project was a website, not a web application, I had no option to select "copy local" when adding the reference.
So my only recourse was to manually copy Telerik.Web.UI.dll into the bin folder and add it to source control. Now when I publish my project, the DLL is where it needs to be, and the error no longer occurs.
By the way, this is not specific to Telerik. I've noticed other people have had similar problems with other DLLs, especially ReportViewer.
Thursday, November 11, 2010
LogParser tricks
Today's example shows how to search the IIS logs. Here's the command line, followed by an explanation and some tips:
G:\Log Parser 2.2>logparser "select date, time, cs-uri-stem, sc-status from g:\logs\www.2l23l.com\W3SVC954531014\ex101110.log where cs-uri-stem like '/hungryboiler%' and time >= '02:00:00' and time < '03:00:00' and cs(User-Agent) like '%Gecko%' and sc-status >= 400"
The fields I wanted to output were date, time, URL (cs-uri-stem) and status (sc-status). Tip: to get a list of all available fields in a log file, use select top 1 * from...
I figured out which log file to search by looking at my website's properties in IIS Manager. In IIS6, on the Web Site tab, under the Logging section, click the Properties button. Then you just need to pick the desired log file according to date. Don't forget: by default, IIS logs use GMT, so something that occurred in the evening Eastern Time will be in the following day's log.
I knew the error occurred on a page whose name started with "hungryboiler", so I searched for cs-uri-stem like '/hungryboiler%'.
I knew a user experienced a "page not found" error, so I searched for sc-status >= 400.
I knew the error occurred between 2:00 and 3:00 AM GMT (10:00 to 11:00 PM the previous day EST), so I search for time >= '02:00:00' and time <= '03:00:00'.
One final tip for LogParser newbies like myself: The query itself goes inside double quotes. Any strings within the query go inside single quotes.
Monday, November 1, 2010
SQL unions and the text data type
I ran into an odd problem related to the text data type. I tried to do a query with a union, something like this:
CREATE TABLE [dbo].[t1](
[c1] [int] NULL,
[c2] [text] NULL
)
CREATE TABLE [dbo].[t2](
[c1] [int] NULL,
[c2] [text] NULL
)
SELECT * FROM t1 UNION SELECT * FROM t2
The SELECT statement fails with this error message: The text data type cannot be selected as DISTINCT because it is not comparable.
A bit odd, because there's no reference to DISTINCT in my query, but SQL Server 2005 must use DISTINCT behind the scenese to perform the UNION.
A workaround is to cast text to nvarchar(max), as in SELECT c1, CAST(c2 AS NVARCHAR(MAX)) AS c2 FROM t1 UNION SELECT c1, CAST(c2 AS NVARCHAR(MAX)) AS c2 FROM t2.
Two drawbacks to this workaround: First, you can't use SELECT *, since you must explicitly name any columns that need to be cast to nvarchar(max). Second, if your text columns happen to hold more data than the capacity of nvarchar(max), I'm not sure what would happen. Either an error message or data loss, I assume.
The real fix would be to change any text columns in your database to nvarchar(max) or some other data type that isn't deprecated and works with unions. That could take a fair amount of work if you have many stored procedures, etc. that refer to the existing text columns.
ReportViewer and ToolTips
- Yes, you can have ToolTips in a report (RDL file) created in SQL Server 2005 Business Intelligence Development Studio (BIDS) and viewed in the .NET ReportViewer control. Just set the ToolTip property for any textbox.
- You can include line breaks in the text of a tooltip. One way to do so is to set the ToolTip property to an expression that uses vbCrLf. Example: ="This is the first line" & vbCrLf & "This is the second line".
- The ToolTips don't show up when you preview the report in BIDS. But they do show up when you run the report in SQL Server Report Services or inside in a ReportViewer control in your .NET program.
Friday, October 15, 2010
Create a PDF and attach it to an email message without saving it to disk
The goal: Use WebSupergoo's ABCpdf .NET 7.0 to create a PDF file on the fly. Without saving the file to disk, attach it to an email message, and send the email.
Prerequisites:
- Create a .NET 3.5 C# web site.
- Configure the mailSettings section in web.config to point to your SMTP server. Don't have an SMTP server? See this handy tip.
- Add a button to a form on your website. Place the code below in the button's Click event handler.
- That's it! But if you're on 64-bit Windows and ABCpdf.NET is throwing an exception, try this.
Here's the code:
// Create a mail message, setting the "from" address, "to" address, subject and body
SmtpClient smptClient = new SmtpClient();
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("ssaporta@localupsolutions.com");
mailMessage.To.Add(new MailAddress("ssaporta@localupsolutions.com"));
mailMessage.Subject = "Test";
mailMessage.Body = "This is a test.";
// Use WebSupergoo's ABCpdf to create a PDF document
Doc theDoc = new Doc();
theDoc.AddHtml("<html><body>The time is now <b>" + DateTime.Now.ToString() + "</b> text.</body></html>");
// Save the document to a memory stream (rather than to a file on disk)
MemoryStream ms = new MemoryStream();
theDoc.Save(ms);
// Important: return to the beginning of the stream
ms.Position = 0;
// Set the MIME type and filename for the attachment
ContentType ct = new ContentType();
ct.MediaType = "application/pdf";
ct.Name = "mydoc" + DateTime.Now.ToString() + ".pdf";
// Create the attachment from the stream
Attachment attachment = new Attachment(ms, ct);
mailMessage.Attachments.Add(attachment);
// Send the email
smptClient.Send(mailMessage);
// Clean up
ms.Close();
theDoc.Clear();
Label1.Text = "Done";
Thursday, October 14, 2010
Cause of exception "Index and length must refer to a location within the string"
By adding a bunch of logging -- trapping exceptions with lots of try/catch blocks and writing them to disk -- I found the problem. This exception can occur when you call the .NET String.Substring() method and the string's length is not long enough.
Something like this would cause it:
string s = "abc";
string s2 = s.Substring(1,5);
In my case, I was parsing a credit card expiration date on the assumption that it would always be formatted as mm/yyyy, but it turned out sometimes the month was a single digit, as in 6/2013 rather than 06/2013.