You are hereProgramming & Web Design / .Net


warning: Creating default object from empty value in /home/hagrinad/public_html/modules/taxonomy/ on line 33.

.Net information

Visual Studio 2010 Conditional Breakpoints with Strings

By hagrin - Posted on 24 December 2011

Here's a really simple tip that isn't exactly readily obvious to novice .Net programmers. You can check out my post on conditional breakpoints in Visual Studio 2005 for a more in-depth explanation as to what a conditional breakpoint is and why you would want to set one.

However, something I didn't cover was "what if I want to have a conditional breakpoint when a string variable is a certain value?". Seems simple enough but if you try something like strVariable = "something" or strVariable == "something", neither will work. So exactly how do you evaluate a string in a conditional breakpoint?

Simply do strVariable.Equals("something"). Intellisense even works!

Happy debugging!

How To: Fix Visual Studio 2008 Design View Hang / Not Working

By hagrin - Posted on 31 May 2010

Recently, I had to do some home .Net development (I mainly do .Net work only at ... work), but when I had some Internet issues and had to work offline, I loaded up my copy of Visual Studio 2008. I opened up my web project and everything seemed to be working fine until I tried to switch to design view on any page or control. Once I tried going to Design View, Visual Studio would stop responding and only a forced quit would close the application. Here's the environmental settings I was working with -

  • Windows Vista Ultimate 64-bit Edition
  • Visual Studio 2008 Service Pack 1
  • Microsoft Office 2010 64-bit

Nothing out of the ordinary as you could see. Obviously, whenever I run into a problem like this, I load up a search engine and search for a solution and found quite a few complaints about this problem. However, after reading the "de facto" solution post from Microsoft, I felt as if I needed to more accurately spell out how to fix this problem since I only found the correct solution after reading through several posts.

  1. Close Visual Studio.
  2. Open up your Control Panel.
  3. Go to your installed Programs and Features.
  4. Look for an entry called Microsoft Visual Studio Web Authoring Component.
  5. Right click on this entry.
  6. Choose Change.
  7. Select the option to Repair.
  8. Re-open Visual Studio and try using design view in your web application.

Obviously, if you don't have this program, you need to install it. Fixing this problem, for me, was really that simple while other posts talked about editing your registry key for Office LastProduct, making sure you had Visual Studio SP1 installed, etc. However, I found that this was the easiest solution that worked for me.

Fixing the "The components for the 64-bit debugger are not registered" Error

By hagrin - Posted on 05 January 2010

Recently, on my new 64-bit home development machine, I fired up Visual Studio 2008 for the first time in a while and decided to start cranking out C# solutions to the Project Euler questions. Since I have already completed 14 questions about a year ago, I was able to code a solution to Question #1 very quickly. I decided to debug the solution and ... wham. I received the following error -

Error while trying to run project: Unable to start debugging.

The components for the 64-bit debugger are not registered. Please repair your Visual Studio 2008 Remote Debugger installation via 'Add or Remove Programs' in Control Panel.

To resolve this issue, you will need your Visual Studio 2008 installation disk. On this disk, you will find the following path -

..\Remote Debugger\x64

Inside this folder should be an executable called "rdbgsetup.exe". Run this EXE, open up Visual Studio and you will now be able to remotely debug your projects.

Exception from HRESULT: 0x800A03EC - Excel, .Net, SQL and Windows Server 2008

By hagrin - Posted on 16 March 2009

For the last 5 days, I have been encountering an error when trying to automate the creation of an Excel document through a scheduled SQL Server job. The error I was receiving was -

Exception from HRESULT: 0x800A03EC

Let's take a step back. The same code I had written worked on my development machine, worked on other target servers while scheduled as SQL jobs, but the code would not work on the following target server -

  • Windows Server 2008 Standard
  • 64-bit platform
  • SQL Server 2005
  • Excel/Office 2007 Professional

After adding some StackTrace code to my program, I was able to determine that the EXE was failing on the Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs line. After trying multiple iterations of the SaveAs command (a quick Google search provided some potential solutions), I continued to get the same 0x800A03EC error code. I went down the road of thinking it was a problem with my 32-bit development environment and had our Sysadmin build me a 64-bit virtual machine for me to compile my application; however, this also yielded the same error. I made sure that the Excel assemblies on the development environment and the target machine were the same version. On the target server, I went to dcomcnfg, selected the Microsoft Excel Application entry and made sure it was using the "interactive user" and still no luck. I made sure that, for testing only, all the SQL services ran under my domain admin account to account for SQL security differences and still nothing.

At this point I decided that I was spinning my wheels and I would call Microsoft and use one of my MSDN support cases.

After speaking to several departments, I finally reached the Office department who tried to help. After explaining my issue quite a few times over and over, I finally got the response I had dreaded - it can't be done that way. Ugh. I had feared I would get this response after reading that using Open XML to create Office documents was the recommended approach and that using the Office COM references was no longer supported (if it ever was) and Windows 2008 has additional security that prevents the old approach from working properly. Well, I guess that explains why it wasn't working.

So where do I go from here? Even though Microsoft support couldn't provide me with sample code or a link to some code, I was able to find this knowledge base article detailing how to to create Excel files using Open XML. Hopefully, this approach will work on my target server environment.

Adding a Link to a SharePoint Document Library

By hagrin - Posted on 03 March 2009

Updated - 13 November 2009 - I have updated this post to improve on the JavaScript listed below so that the Back Button works properly.

Recently, a client wondered how they could add an external document to a document library that existed on their Intranet. The problem with just saving their document and uploading it to the Intranet is a matter of document "freshness" as changes are made by the document owner. Therefore, creating an external link to that document is a much better solution. However, adding a link to a document library would seem difficult on its face.

To get around this issue, I took the following steps -

1. Create a TXT file.
2. Open the TXT file and add the following HTML -

<title>External Link</title>
<script type="text/javascript">

3. Save the file as a HTML file.
4. Upload to your Document Library.

You now have a working JavaScript redirection to the external document in your document library. Also, you can click the Back Button in your browser and you will return back to your Document Library.

Create a Word 2003 Document Using VB.Net

By hagrin - Posted on 04 August 2008

The following code will help you create a very basic Word 2003 document using VB.Net. In addition to the code below, you will need to make sure that Office is installed on the host running the application for the document to be created.

Dim word As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
doc = word.Documents.Add()
Dim range As Microsoft.Office.Interop.Word.Range = doc.Range(Start:=0, End:=0)
range.Text = "Put your document's text here."
doc.SaveAs("Path and File Name")

Create an Excel 2003 Workbook Using VB.Net

By hagrin - Posted on 04 August 2008

The following contains code on "How to Create an Excel 2003 Workbook Using VB.Net". Remember, you will need to add the "Import Microsoft.Office.Interop" reference at the top of your code. In addition, you will need sufficient rights to create files in your desired save location as well as Office installed on the machine hosting the application.

Dim MyEx As New Excel.Application
Dim MyBook As Excel.Workbook
Dim MySheet As Excel.Worksheet
MyEx.DisplayAlerts = False
MyBook = MyEx.Workbooks.Add
MySheet = MyBook.Sheets.Add
MySheet.Name = "Worksheet Name"

'Entering static values into cells as headers
MySheet.Cells(1, 1) = "Header 1"
MySheet.Cells(1, 2) = "Header 2"
MySheet.Cells(1, 3) = "Header 3"
MySheet.Cells(1, 4) = "Header 4"
MySheet.Cells(1, 5) = "Header 5"
MySheet.Cells(1, 6) = "Header 6"

'Reading through a data set to fill in the rest of the worksheet
For i = 0 To DataSet.Tables(0).Rows.Count - 1
   MySheet.Cells(i + 2, 1) = DataSet.Tables(0).Rows(i).Item(0)
   MySheet.Cells(i + 2, 2) = DataSet.Tables(0).Rows(i).Item(1)
   MySheet.Cells(i + 2, 3) = DataSet.Tables(0).Rows(i).Item(2)
   MySheet.Cells(i + 2, 4) = DataSet.Tables(0).Rows(i).Item(3)
   MySheet.Cells(i + 2, 5) = DataSet.Tables(0).Rows(i).Item(4)
   MySheet.Cells(i + 2, 6) = DataSet.Tables(0).Rows(i).Item(5)

MyBook.SaveAs("FileName.csv", FileFormat:=Excel.XlFileFormat.xlCSV)
MySheet = Nothing
MyBook = Nothing
MyEx = Nothing

Conditional Breakpoints in Visual Studio 2005

By hagrin - Posted on 04 August 2008

Sometimes when you are self-taught, you may know how to do something, but you do it the hard way. Therefore, sometimes even the smallest little feature you didn't know about can really make your day and improve your coding efficiency. Today, I stumbled over the addition of conditional breakpoints in Visual Studio 2005. Now, I'm sure any serious coder probably already stumbled over this feature, but I had not until today. A conditional breakpoint is exactly what it sounds like - it is a breakpoint that will be triggered during the debugging process only when a condition you specify is met.

Conditional Breakpoints in Visual Studio 2005

Using Visual Studio 2005, you can set a conditional breakpoint by placing a breakpoint on a desired line much like you have in the past (click the gray area to the left of the desired line). A red dot will appear representing the breakpoint. When a user right clicks on the breakpoint, you will be presented with a list of options that include:

  • Delete Breakpoint
  • Disable Breakpoint
  • Location
  • Condition
  • Hit Count
  • Filter
  • When Hit

Anyone who used Visual Studio 2003 as their primary development environment would be surprised to see all these new options in the 2005 version. If you choose the "Condition" option, you will be presented with a dialog box that asks you to input a condition and to choose whether the condition "Is True" or "Has Changed".

Conditional breakpoints are extremely important for debugging problems that exist in WHILE loops, FOR ... NEXT loops, etc. especially when dealing with extremely large loops. Say you have a single record bombing out in a huge loop and you are being emailed the CATCH exception. Instead of setting a breakpoint and continually hitting F5 to eventually get to the record that your application is bombing out on, you can now just set a conditional breakpoint, run your application and have the debugger stop the process right as you get to the problem record.

I'm excited to have "discovered" (yeah, I know, I'm late to the dance on this one) this feature as it should drastically improve my debugging and shorten troubleshooting time. Hopefully, if you weren't already aware of this feature, you are now and will help you in your .Net development.

VB.Net 2.0, SQL Server 2000 & Windows Application SQL Error

By hagrin - Posted on 11 May 2007

Today, I started working on an application to perform bulk changes to our Deltek Vision database to change tasks, sub-tasks, budgets and billing terms. So, as I go to write the SQL connection string, something I have done 100s of times, I kept getting the following error from my app:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

While the error is pretty descriptive, there is one slight problem - I'm not trying to access a 2005 SQL Server, but a SQL Server 2000 box. So, I do what any good programmer does - he searches the major search engines for a solution, but most of the examples are of users trying to 1) build a Web application and have a web.config error or 2) are actually trying to access a SQL Server 2005 database. Yikes, now what?

I can't stress this enough - check your connection string. I was actually passing a blank Data Source (I was using SelectedValue as opposed to SelectedItem) and since I have SQLExpress running on my development machine, I assume that's why I was generating a 2005 error when trying, in theory, to connect to a SQL 2000 machine. The lesson is - verify your connection string when getting this error and trying to access a SQL 2000 machine. If you're trying to access a SQL 2005 machine, follow the enabling remote connections info that you'll find on the hundreds of pages that come up in he search engines for this error.

Convert .Net Code to HTML

By hagrin - Posted on 03 May 2007

When you're writing a development related blog, you're eventually (hopefully) going to write some code snippets that you want to share with your readers. However, in order to get the most out of that code snippet, you should make it easy to read and color coded so that potential users can quickly read through your code and evaluate its worth.

That's where CopySourceAsHTML will solve all your problems. CSAH is a plug-in that integrates directly into your Visual Studio IDE environment and allows you to highlight code, right click and choose "Copy As HTML". The tool is freeware and performs exceptionally - if you maintain a .Net developer blog, I would suggest installing this add-on.