Archives
-
SQL Server encountered error 0x80070422 while communicating with full-text filter daemon host (FDHost) process.
When trying to do a full text search with SQL Server 2008 I received this error:
SQL Server encountered error 0x80070422 while communicating with full-text filter daemon host (FDHost) process. Make sure that the FDHost process is running. To re-start the FDHost process, run the sp_fulltext_service 'restart_all_fdhosts' command or restart the SQL Server instance.
I was able to track this down to the SQL Full-text Filter Daemon Launcher service being disabled. Enabling and starting the service resolved the issue for me.
It is interesting to note that the service is set to a Startup Type of Manual but after a restart of my machine the service is started, so SQL Server 2008 must be starting it. Having the service disabled probably prevented SQL Server from starting it the first time I went to run a full-text search.
See this post (SQL Server encountered error 0x80070422 (FIXED)) for the same error message but I did not do all the steps he did (I just enabled and started the service).
Technorati Tags: SQL Server Full-text Search -
How to change the Target Framework Version for a Visual Basic Project
Today I received the following warning message from Visual Studio while adding a reference in a Visual Basic project:
The Target Framework version for the project ‘XXXX’ is higher than the current Target Framework version.
Would you like to add this reference to your project anyway?This warning message makes complete sense since the Visual Basic project I was working on is targeting the .NET Framework 2.0 and the project that was being referenced targeted the .NET Framework 3.5. The only issue was that I was not able to figure out how to change the Target Framework Version in a Visual Basic project.
In a C# project it is pretty easy; right-click on the project and choose properties and in the Application tab (vertical tab) you will see the Target Framework dropdown box:
But in Visual Basic it is hidden. Here is where I found how to change the Target Framework version after searching for a bit:
Right-click on the project and choose properties and then select the Compile tab (vertical tab).
At the bottom of the Project > Compile tab you will find an Advanced Compile Options… button.
In this dialog called the Advanced Compiler Settings is where you will find how to change the Target Framework version for Visual Basic.
-
GDI+ Error when converting Tiff to Jpeg: Parameter is not valid
One of the web applications that I work on is Instant Church Directory, a website that helps churches create a church photo directory. Since the main focus of the application is to create a photo directory, customers are uploading all sorts of images into Instant Church Directory and the application needs to correctly convert and store the images and insert them in the final output, which is a PDF.
Since the web application was launched in September 2008 we have had an issue with some Tiff images that are uploaded and throw a System.ArgumentException when the image is converted to a Jpeg.
System.ArgumentException: Parameter is not valid. at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(Stream stream, ImageFormat format)
Today I was finally able to track it down to the Tiff image being created (or modified) by Adobe Photoshop and Adobe Photoshop is adding extra Property Items (meta data tags) into the image.
With the help of Bob Powell’s tool: Discovering the Property Items present in an image, I was able to see that the Adobe Photoshop Tiff images included several additional property items that were not present in other Tiff images that worked. Removing the tags from the original image prior to converting it to a Jpeg resolved the issue.
Here is a list of all of the Microsoft Windows GDI+ image property tags in numerical order.
The PropertyTagICCProfile is id 0x8773 and the other tag that I removed to resolve this issue is id 0x935C (this Property Item is not defined in the list above but it has a header in it with “Adobe Photoshop Document Data Block”). Property Items 0x02BC and 0x8649 are also not defined in the GDI+ list above and also are added by Adobe Photoshop but they did not cause any issues so I just left them (although if removing the first two do not work for you then try removing the other two also).
Here is the code that I used to remove the offending Property Items from the Tiff image before converting it to a Jpeg in order to prevent the GDI+ Parameter is not valid exception:
// Check if this is a Tiff file
if (bmp.RawFormat.Guid.Equals(ImageFormat.Tiff.Guid))
{
//loop through all of the Properties
//looking for the offending property items added by Photoshop
foreach (PropertyItem pItem in bmp.PropertyItems)
{
switch (pItem.Id)
{
//ICC Profile tag (PropertyTagICCProfile)
//Remove this tag for Tiff to be converted to Jpeg.
case 0x8773:
bmp.RemovePropertyItem(0x8773);
break;//Unknown tag added by Adobe Photoshop
//"Adobe Photoshop Document Data Block".
//Removing this tag for Tiff to be converted to Jpeg
case 0x935C:
bmp.RemovePropertyItem(0x935C);
break;default:
break;
}
}
}//convert the image to jpeg
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
bmp = new Bitmap(ms); -
Amazon is offering free one-day shipping for the Kindle
I love this. Amazon is offering free one-day shipping for their Kindle starting tomorrow December 23. This means you can buy the Kindle up until midnight (EST) on December 23, 2009 and still have it delivered in time for Christmas. (There is free 2-day shipping if you buy it today.) What an awesome way to bring in new customers.
Kudos to the Amazon marketing team for coming up with this marketing idea. But I think the real credit should go to all of the Amazon people who made the free one-day shipping a reality. I am sure tons of marketing people have had the idea to use free one-day shipping right before Christmas to promote a product but have not had the behind the scenes infrastructure to actually pull it off.
Check out the count down clock on their home page too:
-
StackOverflow to Google Index in 30 minutes
This is pretty amazing. I asked a question on StackOverflow and 30 minutes later (while I was still trying to find the answer on my own) I found my question indexed in Google’s search results. WOW!
Bing didn’t have my StackOverflow question… but it did have an answer for me.
+1 for Google getting my StackOverflow question indexed so fast.
+10 for Bing getting me the answer. -
jQuery: How to check if button is disabled
You can use jQuery to trigger a button click from the client. In this certain situation, I needed to make sure the button was not disabled prior to clicking. In jQuery you can use the “is” function to check if the button is disabled like this:
<script type="text/javascript">
$(document).ready(function() {
if ($('#StartButton').is(':disabled') == false) {
$('#StartButton').click();
}
});
</script>Technorati Tags: jQuery -
Changing up how my Someday/Maybes are organized
I am a big fan of Getting Things Done (GTD) and highly recommend the GTD book and the methodology to everyone and anyone.
I do not consider myself a GTD Black belt yet but I am continually progressing and getting better and better at GTD each and everyday. One of the areas of GTD that I consider to be my weakest is the Organize part of GTD. I tend to resist moving projects and next actions that are truly someday/maybes into my someday/maybe list. This is because my someday/maybe list has become so large that I do not review it regularly and no longer is it a trusted part of my GTD system.
But I am also a big fan of keeping things flat. I want to keep the overhead associated with running a GTD system at a minimum and having everything flat is a huge win for me in this area. Up until now I had a single someday/maybe section (I use OneNote) for all of my someday/maybes but it definitely has become overwhelming and I am resisting putting things into the blackhole that is my someday/maybe list.
I am going to try separating them into the various roles that I have:
- Developer
- Husband
- Father
- Homeowner
- Entrepreneur
I will see if this will allow me to keep my Next Action and Project list clean by feeling completely comfortable moving a stale item into my someday/maybe list (now that I can review these regularly… something I was not doing to my someday/maybes which is why I resisted moving items there in the first place).
Technorati Tags: GTD,Getting Things Done -
Amazon Same Day Shipping
Back in October I heard that Amazon was introducing same day
shippingdelivery for some cities. Today I received an email for being an Amazon Prime member reminding me that Amazon has the ability to deliver an item to me within the same day. But what is really amazing is the cut-off times; in Seattle you can order an item up to 1PM and get it delivered to you that same day:That is amazing! Talk about reducing the friction in buying… Amazon is an expert! Just ask me how many items I bought for Christmas through Amazon Prime just because I get free two-day shipping.
Technorati Tags: Amazon Same Day Shipping -
Where to find the Subversion Binaries (svn.exe)?
I was setting up CruiseControl.NET for the Vaasnet automated build system and I needed the Subversion binaries. This is my first project that I had used Subversion for source control and up until now I had just been using TortoiseSVN for interacting with the source control repository.
CruiseControl.NET needs the Subversion binaries since this is how it communicates with your Subversion repository (through svn.exe). Finding just the binaries ended up being a particularly difficult task. Eventually I figured it out… posting here for anyone else that also runs into this issue:
Start here:Tigris.org – Getting SubversionHead down to the Windows section and click on the Tigris.org link:Look for the latest version MSI installer (at the time this post was written v. 1.6.6)Run this installation app and you will get svn.exe installed on your machine.On Windows Server 2008 64-bit the default install path will be:C:\Program Files (x86)\Subversion\bin\svn.exe
Hopefully this will help someone else in the future.
EDIT (2011-01-25): Alec Taylor found up to date ones here:
- http://nightlybuilds.tortoisesvn.net/latest/x64/small/
- http://nightlybuilds.tortoisesvn.net/latest/win32/small/
EDIT (2012-01-27):
See http://nightlybuilds.tortoisesvn.net/ for instructions on the correct folder for the stable release. The "latest" folder is the nightly build.
Technorati Tags: Subversion,svn.exe -
URL Authorization role service required for IIS7 system.webServer/security/authorization
Why isn’t IIS7 authorization working in my asp.net website? I was trying to secure a folder in my asp.net application using the IIS7 system.webServer/security/authorization configuration settings. In the past you could do this through the ASP.NET configuration by adding an authorization section to the system.web section in your web.config. But now with IIS7, you can use the new system.webServer/security/authorization section to specify authorization rules. The benefit of system.webServer authorization over system.web authorization is that the former applies for all requests to that particular location, the latter only protects asp.net requests (requests that come through the asp.net pipeline).
So, since I am developing this application on IIS7, I wanted to use the new IIS7 system.webServer authorization section to protect a particular folder. To do this, I added the following section to my web.config file:
<location path="admin">
<system.webServer>
<security>
<authorization>
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="" roles="administrators" />
</authorization>
</security>
</system.webServer>
</location>and tested the url http://localhost/admin and… it didn’t work. What should have happened is I should have been redirected to the forms authentication login page, but instead I was served the content under the /admin folder. Not what I wanted; the /admin folder should now require an authenticated user and the forms authentication identity to be part of the administrators role.
What is going on?!?!? Everything looked correct. I confirmed that IIS authentication was set correctly: anonymous and forms authentication only. I confirmed that the system.web/authorization section was working. I tried in multiple browsers to make sure it wasn’t a cookie or a caching issue. Still I was left scratching my head… why were settings in the IIS7 system.webServer/security/authorization not getting picked up?
Finally, with the help of Scott Forsyth, I checked the Server Manager IIS Roles that were enabled. Server Manager > Roles > Web Server (IIS) > Add Role Services
Notice that the URL Authorization role service is not installed.
That was it. IIS7 did not have the role service installed so it was not understanding that section of the web.config file.
After installing the IIS URL Authorization role service, a request to http://localhost/admin redirected to the forms authentication login page and required a user that was in the administrators role.
-
CruiseControl.NET Configuration Reference
For some reason it is very difficult for me to find the CruiseControl.NET configuration reference online. Most of the time I end up on an older reference which is out of date and just not correct.
This is the CruiseControl.NET reference that appears to be up-to-date:
CruiseControl.NET Configuration Reference
http://confluence.public.thoughtworks.org/display/CCNET/The+CruiseControl+Configuration+BlockOn the bottom of each page is a list of the children for each configuration block and at the top is the breadcrumb for how far you have drilled down into the tree.
And then you can view the full CruiseControl.NET configuration hierarchy here.
This blog post is mostly for me but also, if I am having a tough time finding the reference then I imagine a lot of other people are too.
-
Prevent CruiseControl.NET error “Source control operation failed: Working copy locked svn”
My CruiseControl.NET build system was running into an error whenever two projects were trying to build at the same time. Both of these projects try to go out to our subversion source control repository and one will win and the other gets locked out.
The build will then fail with this type of error:
ThoughtWorks.CruiseControl.Core.CruiseControlException: Source control operation failed: svn: Working copy 'XXXX' locked svn: run 'svn cleanup' to remove locks (type 'svn help cleanup' for details) .
To get around this issue you can use the “queue” attribute of the project node:
Here is the Thoughtworks CruiseControl.NET Project configuration reference section: http://confluence.public.thoughtworks.org/display/CCNET/Project+Configuration+Block
Originally I did not set a queue value for each project that is built. The default in this instance is the project name, so each project ends up in its own queue and therefore they will build as soon as possible and cause the locking error.
From the Thoughtworks reference:
queue
The name of the integration queue that this project will use. By default, each project runs in its own queue. (Added in CCNet 1.3)So by setting the queue for each of the projects to the same value (since all of the projects are related), each of them will wait and build one at a time, resolving the “Source control operation failed: svn: Working copy 'XXXX' locked svn” error.
Note: You can also set the queuePriority to indicate the order the project should build when it is in the queue.
This StackOverflow post lead me to this solution: How can I prevent concurrent builds in CruiseControl.NET?
-
Handle the button click event from an ASP.NET ListView control
Here is how you can handle the event of a button from within an ASP.NET ListView control.
Add your button to the ListView Template like you would any other control:
<asp:ListView ItemPlaceholderID="Test" runat="server" ID="ListView1" >
<ItemTemplate>
<asp:Button runat="server" Text='<%# Eval("MyProperty") %>' CommandArgument='<%# Eval("MyProperty") %>' /><br />
</ItemTemplate>
</asp:ListView>And then handle the ListView.ItemCommand event in your code:
That is really all there is to it. The ListView will bubble up the Button’s click event to the ListView_ItemCommand event handler and then you can handle it there. You can also use the CommandArgument property to send button specific data, such as the particular ID of the row or item that the user clicked the button for.
This call also be used on some of the other databound controls such as the ASP.NET Repeater.
Full Example Code:
ListViewButtonExample.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListViewButtonExample.aspx.cs" Inherits="ListViewButtonExample" %>
<html>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ItemPlaceholderID="Test" runat="server" ID="ListView1" >
<LayoutTemplate>
<asp:Literal runat="server" ID="Test"></asp:Literal>
</LayoutTemplate>
<ItemTemplate>
<asp:Literal runat="server" Text='<%# Eval("MyProperty") %>'></asp:Literal>
<asp:Button runat="server" Text='<%# Eval("MyProperty") %>' CommandArgument='<%# Eval("MyProperty") %>' /><br />
</ItemTemplate>
</asp:ListView>
<asp:Literal runat="server" ID="Literal1"></asp:Literal>
</div>
</form>
</body>
</html>ListViewButtonExample.aspx.cs:
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Collections;public class MyObject
{
public String MyProperty { get; set; }
}
public partial class ListViewButtonExample : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
ListView1.ItemCommand += new EventHandler<ListViewCommandEventArgs>(ListView1_ItemCommand);
}void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
Literal1.Text = "You clicked the " + (String)e.CommandArgument + " button";
}protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<MyObject> col = new List<MyObject>();
col.Add(new MyObject { MyProperty = "test 1" });
col.Add(new MyObject { MyProperty = "test 2" });
ListView1.DataSource = col;
ListView1.DataBind();
}
}
}Technorati Tags: ListView,ItemCommand Event -
IIS7 Search Engine Optimization Toolkit does not like HTML5 Doctype
The IIS7 Search Engine Optimization (SEO) Toolkit is an awesome tool to review your site and indicate any problems with the html that may cause search engines not to index your website properly. Check out Scott Guthrie’s post on the IIS7 Search Engine Optimization Toolkit or you can download it from the IIS website at the tool’s home: IIS7 SEO Toolkit.
But I ran into an issue with the tool the other day where it was not returning the proper results. I ran it against a website I was working on and it only crawled one page and returned results that were just not correct:
The errors: “The title is missing.”, “The description is missing.”, and “The <h1> tag is missing.” were incorrect since I had all of those on the home page of the site I was testing, but also it was curious that it was not crawling any other urls off of that home page.
AND the content tab even showed all of these things in the html that the tool had retrieved:
Eventually I was able to track it down to using the HTML5 Doctype tag:
<!DOCTYPE html>
The HTML5 document type is not official yet but I have gone ahead and started using as recommended by many developers but apparently the IIS7 SEO Toolkit does not like this doctype yet. Temporarily I switched it to another doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
And the SEO Toolkit worked as expected. Just a heads up for any other developers that run into this when using HTML5 DOCTYPE.
UPDATE (2009-12-07):
Dave Cox added a comment about it not being the HTML5 DOCTYPE per say but the whitespace that comes before it. Having a line of whitespace AND the HTML5 DOCTYPE causes the IIS7 SEO Toolkit not to read the content correctly.
I am using ASP.NET MVC in this project so that means my master page will look like this; the DOCTYPE declaration on the same line as the Master page directive:
-
Visual Studio Error: The project file ' ' has been renamed or is no longer in the solution.
I received the vague error message “The project file ' ' has been renamed or is no longer in the solution” while building a Visual Studio solution. I was unable to build any projects in the solution. Rebuild and Clean were not working and were responding with the same message.
---------------------------
Microsoft Visual Studio
---------------------------
The project file ' ' has been renamed or is no longer in the solution.
---------------------------
OK
---------------------------After a bunch of searching around and hair pulling, I was able to narrow it down by removing all projects from my solution and slowly adding them back in one at a time and rebuilding between each one. Eventually I tracked it down to the web application project I had in my solution, specifically the Silverlight Applications tab in the Project Properties.
What had happened was I removed a Silverlight project from my solution that was no longer needed but the Web Application project still had a reference to it. Not sure why the name of the project got removed but it certainly made it difficult to understand the error message.
By removing these two project references from the Silverlight Applications tab, the error message went away and I was able to build the solution.
I hope this helps someone else out there.
Technorati Tags: Visual Studio,Silverlight Applications Project Properties Tab -
How to show white space in Visual Studio
In Microsoft Word I usually have the paragraph symbol turned on to Show Hidden Formatting Symbols (white space) so that I can clearly see spaces, tabs, and other white space characters.
Up until recently I had no idea that Visual Studio had the same option to display white space. Jeff Atwood’s recent blog post Whitespace: The Silent Killer had a screen shot on some code showing white space characters, so I hunted around in the Visual Studio toolbars for a little bit and found the option under the Edit menu.
Edit > Advanced > View White Space
You can also use Ctrl+R, Ctrl+W to toggle it on and off.
Technorati Tags: Visual Studio,Visual Studio Tips and Tricks -
ISO 3166-1 Country Data SQL Script
I am creating a standard sign up form with one of the fields being a country drop down. So I created my Country database table and then needed to fill it with information. I found the ISO list of countries here, but then the issue was how to get that list into my Country database table. Luckily someone has already done that for me: http://vidmar.net/weblog/archive/2008/05/23/database-of-country-names-numeric-alpha-2-and-alpha-3-iso-codes.aspx
But I also like to be able to check a script like that into source control to be able to track changes to it. So I updated the insert script to be a rerunnable insert/update script. The script will check if a country id exists and if it does not exist, then it will insert the country otherwise it will just do an update. The insert sql script from http://vidmar.net/weblog/archive/2008/05/23/database-of-country-names-numeric-alpha-2-and-alpha-3-iso-codes.aspx really got me most of the way there so I need to give a lot of credit to him.
The link below will get you my updated version of the country data update sql script. I also updated it to 2010 from the ISO 3166 code lists plus any changes that they have posted so it is up to date as of May 15, 2010. I will try (but no promises) to keep it updated on a regular basis. Feel free to contact me if you want to try and keep it updated for me and I will post it here.
Click here for the country data update sql script (up-to-date as of May 15, 2010).
You can use this sql to create the Country table:
CREATE TABLE [dbo].[Country]
(
CountryId int NOT NULL,
Iso2 char(2) NOT NULL,
Iso3 char(3) NOT NULL,
Name nvarchar(64) NOT NULL,
DateCreated datetimeoffset(7) NOT NULL CONSTRAINT [df__Country__DateCreated] DEFAULT (sysdatetimeoffset()),
DateModified datetimeoffset(7) NOT NULL CONSTRAINT [df__Country__DateModified] DEFAULT (sysdatetimeoffset())
)ALTER TABLE dbo.Country ADD CONSTRAINT
pk__Country__CountryId PRIMARY KEY CLUSTERED
(
CountryId ASC
) WITH FILLFACTOR = 100 ON [PRIMARY]Technorati Tags: ISO 3166 Country Codes,SQL Scripts -
Generating a random strong password
You can use the ASP.NET Membership provider to generate a new random strong password.
In the past I have usually either rolled my own authentication system or integrated an asp.net authentication system into an existing application and therefore I did not use the ASP.NET Membership system. In the current application I am writing, I had a need to generate a random strong password for the customer.
The ASP.NET Membership system already has a static method built-in for this. You can use the GeneratePassword static method from the Membership class to create a new password:
String strongPassword = System.Web.Security.Membership.GeneratePassword(8, 1);
From the MSDN documentation, the two parameters are:
- length – Int32
- The number of characters in the generated password. The length must be between 1 and 128 characters.
- numberOfNonAlphanumericCharacters – Int32
- The minimum number of punctuation characters in the generated password.
Also from the documentation: the generated password will contain alphanumeric characters and the following punctuation marks: !@#$%^&*()_-+=[{]};:<>|./?.
But also not included in the documentation is that the returned password will not be a “dangerous string”; in other words it won’t look like a block of script.
The Membership.GeneratePassword checks the newly generated password string using an internal method called CrossSiteScriptingValidation.IsDangerousString() and will not return a password that does not pass this test. It will just loop and continue to generate a new one until it is not considered a dangerous string. Pretty cool stuff!
-
Canon Scanner – Unable to open TWAIN source
I have a Canon CanoScan 4400F Scanner and the other day I was unable to get it to work. I use the Canon software CanoScan Toolbox to operate the scanner and when trying to scan I was getting the following error message:
---------------------------
CanoScan Toolbox
---------------------------
Unable to open TWAIN source
Please check connection
Then re-start Toolbox
---------------------------
OK
---------------------------Searching the Internet for this problem turned up several people having the same problem and several solutions which looked like they may or may not work. One of the recommended solutions was to make sure a certain folder path is in your PATH environment variable. As it turned out this was the problem, so here is how to add that path back into your environment variables.
First, determine the correct path to add into the PATH environment variable. Look in C:\Windows\twain_32 and there should one other folder in there. In my case it was named CNQ4803.
This is the path that is needed to be added into the PATH environment variable.
C:\Windows\twain_32\CNQ4803
Now, follow these instructions to get to the dialog to modify the PATH environment variable.
Control Panel > System > and then choose Advanced System Settings in the left hand column.
This will bring up the System Properties dialog (it should already be on the Advanced tab).
At the bottom of this dialog is an Environment Variables button. Clicking this button will bring up the Environment Variables dialog.
In the bottom panel, scroll until you find the variable named Path. Select this one and then hit the Edit… button to bring up the Edit System Variable dialog.
In the Variable value text box, scroll all the way to the right and then add in the path C:\Windows\twain_32\CNQ4803 that was determined earlier. Make sure to separate this value with a preceding semi-colon. And also be careful not to make any other changes to this value.
Now OK your way out of all of the dialogs and CanoScan Toolbox will now work as expected.
Technorati Tags: Canon Scanner CanoScan Toolbox,Environment Variables
-
Machine Setup: Turn-off clicking sound when browsing folders
In the past I usually have had the sound turned off on my computer but recently I have been leaving it on. With the sound on, browsing folders in Explorer or navigating in Internet Explorer would play a clicking sound whenever changing folders or navigating to a new page. That gets annoying very quickly so here is how I shut it off on Windows Server 2008 (and probably Windows Vista too):
Start > Control Panel > Sound
In the Sound Control Panel, select the Sounds tab and then in the Program panel scroll all the way down to the “Windows Explorer” program (it will be near the bottom).
Under the Windows Explorer program is a “Start Navigation” sound:
Select this one (you can use the Test Button to confirm that you have the correct sound) and then change the Sounds dropdown near the bottom to “(None)”.
Hit Apply and OK your way ok of the Sound Control Panel and now no more clicking sound while browsing folders in Explorer or while navigating in Internet Explorer.
This is getting added to my Machine Setup checklist for when I rebuild my development environment.
Technorati Tags: Windows Server 2008 Sounds,Machine Setup -
How to quickly comment or uncomment lines of code in Visual Studio
When I am developing I am always trying to reduce the amount of time that my hands come off of the keyboard and have to move to the mouse. One of the frequent functions that I noticed required me to move my hand off of the keyboard to the mouse is commenting or uncommenting lines of code.
Visual Studio has two buttons in the toolbar to comment or uncomment a line of code (they are part of the Text Editor or HTML Source Editing Toolbars):
You can also achieve the same result by using the key combination Ctrl-K, Ctrl-C to comment out the currently selected lines or Ctrl-K, Ctrl-U to uncomment the currently selected lines.
Ctrl-K, Ctrl-C means to hold down the Control key and then press K and then while still holding down the Control key press C. Ctrl-K, Ctrl-U means to hold down the Control key and then press K and then while still holding down the Control key press U.
I have found this key combination to be difficult at first to remember (in the past I tended to always just instinctively go for my mouse) but now I have remembered to use that key combination regularly and have found it very helpful.
-
How to send email when port 25 is blocked
I run Windows Server 2008 as my development environment and use the local SMTP service to send emails for any website or application that I am developing and that needs to send email. Recently I was working on a Billing Application that needed to send emails and I wanted to send several to myself for testing, but for some reason the emails were not being sent.
I followed this article from Scott Forsyth about how to debug smtp issues. After connecting using Telnet and manually sending a message, I saw the email message sitting there in my queue (C:\inetpub\mailroot\Queue) and not going out.
Next I checked the event log and found this message (I was sending to a gmail account for testing):
Message delivery to the host 'XXX.XX.XXX.XX' failed while delivering to the remote domain 'gmail.com' for the following reason: The remote server did not respond to a connection attempt.
This indicated that my local smtp server was not able to connect to gmail’s mail server. I use Verizon Residential DSL as my Internet Service Provider (ISP). Some time in 2009, Verizon Residential DSL began blocking port 25. This caused my local development machine SMTP server to not be able to send email.
An easy workaround that I found was to send using my Verizon DSL email account. To do this you need to specify port 587 and also your credentials for your Verizon account:
System.Net.Mail.SmtpClient smtpClient = null;
smtpClient = new System.Net.Mail.SmtpClient("outgoing.verizon.net", 587);
smtpClient.Credentials = new System.Net.NetworkCredential("account@verizon.net", "password");
smtpClient.Send(m);
Verizon lets you create multiple email accounts so it was easy to create a secondary account just for me to send through instead of using my primary account.
Technorati Tags: Verizon Residential DSL,Smtp Client -
Machine Setup: How to enable Line Numbers in Visual Studio and SQL Server Management Studio
I like to have line numbers visible when working in both Visual Studio and SQL Server Management Studio. By default, line numbers are turned off in both environments. One of the first things I do when setting up a new development machine is to open Visual Studio and SQL Server Management Studio, enable line numbers, and then close both of them so that the setting is saved for the future.
In Microsoft Visual Studio, to enable line numbers open the Options dialog by going to Tools > Options…
Then expand the Text Editor node and then the All Languages node. Now you will see a Line Number checkbox under the Display section on the right-hand side. Check this box to display line numbers.It is a nearly identical procedure to enable line numbers in Microsoft SQL Server Management Studio:
Tools > Options… > Text Editor > All Languages > Line Numbers checkboxTechnorati Tags: Visual Studio,SQL Server Management Studio -
How to quickly format a C# class file – Ctrl-K, Ctrl-D
In C# as you are typing in a class file the indenting of your code can easily get out of alignment making the code hard to read. Where does your class, if block, or method begin and end??
You can manually go and fix each line but there is a much simpler way to correct the indenting. You can use Ctrl-K, Ctrl-D to format the entire document. Now your code will be reformatted to the correct indenting for your page.
Couple things to note:
- If there are errors in the structure of your code (missing closing brackets, missing semi-colon, etc.) then this will not work. This will still work with other errors such as undeclared variables.
- If you are working on legacy code (for example fixing a bug) and there is a different indenting structure, it is good practice to stick with the legacy indenting and not modify the indenting of the entire file just because you fixed a bug in one line of code. You should try to minimize your code change to only what was necessary to fix the bug (don’t reformat the entire file). The next person that does a diff on your check-in with the previous check-in will thank you.
- I also leave the Visual Studio indentation settings alone and stick with the defaults. If you have a different indentation style than a code file that was previously checked, this process could also cause the subsequent diff to show lots of red.
- You can use Ctrl-K, Ctrl-F on smaller blocks of text, so if you have a strange indenting style then highlighting only your change can correct the indentation on the selected lines and not the entire file.
- These can be found under the Edit > Advanced Menu:
- Cutting and Pasting is also another way to get the content formatted quickly:
- Ctrl-A, Ctrl-X, Ctrl-V
Technorati Tags: Visual Studio Tip and Tricks -
Use Ctrl+. (period) to trigger Visual Studio’s automatic add using statement context menu
When you type class names that are missing the correct namespace reference, Visual Studio will help you out by giving you a context menu that you can use to automatically add the correct using statement to the top of your class.
For instance, in the example below, the Utility class exists in a different namespace that is not currently referenced in the class. Visual Studio gives you the red squiggly to show there is an error but there also is a small little line at the end of the class name:
You can take your mouse and hover just over that line and you will get a little drop-down context menu:
Which is a very nice feature where Visual Studio will automatically add the using statement to the top of your file (or insert the full reference):
The feature to add the using statement to your class is great in itself but getting your mouse into just the right spot to click that little line is pretty tricky (and also can break your development train of thought).
As the tool tip says, you can hit Shift+Alt+F10 to get the context menu but Ctrl+. (period) will also pop up that menu and it is a much easier key combination to use.
-
All of Kramer’s entrances on Seinfeld
Every single Kramer entrance:
Thanks to the blog The Big Picture by Barry Ritholtz for pointing me there.
-
Timestamp string with milliseconds from a System.DateTime
You can easily convert a System.DateTime object into a string based on the current date and time by using the ToString() method of the DateTime object. For instance:
DateTime d = DateTime.Now;
String s = d.ToString("yyyyMMdd-HHmmss");Will produce a string with the value of “20091018-232013” assuming the date/time was 10/18/2009 11:20:13PM at the time the code was executed.
But did you know you can get the milliseconds of that System.DateTime object by using the “fff” format string:
DateTime d = DateTime.Now;
String s = d.ToString("yyyyMMdd-HHmmss.fff");Will produce a string with the value of “20091018-232013.456” assuming the date/time was 10/18/2009 11:20:13.456PM at the time the code was executed.
I use this all the time when I need to append a timestamp to a log, a log filename, or just anything else that needs a quick way to turn a System.DateTime object into a string with milliseconds too.
Technorati Tags: System.DateTime.ToString() -
Parse a non-standard date string into a System.DateTime object
The other day I had a date that was in the form of yyyyMMdd and I needed to parse that string into a System.DateTime object. Just trying to parse the string into a System.DateTime object would not work:
String dateString = "20091016";
DateTime d = DateTime.Parse(dateString);The above code results in an exception:
FormatException: String was not recognized as a valid DateTime.
I was guaranteed to have the date string in the form of yyyyMMdd so my initial thought was to use Substring to break it into the individual year, month, and day parts and create a new System.DateTime object from those pieces.
But then I discovered that you can use the DateTime.ParseExact method and a System.Globalization.DateTimeFormatInfo object to specify the pattern for the date that is being parsed.
Here is how I was able to parse a non-standard date string into a System.DateTime.
System.Globalization.DateTimeFormatInfo di;
di = new System.Globalization.DateTimeFormatInfo();
di.FullDateTimePattern = "yyyyMMdd";String dateString = "20091016";
DateTime d = DateTime.ParseExact(dateString, "F", di);By the way, this is also a great way to parse a credit card expiration date that is in the form of MMyy to a System.DateTime. Just use a pattern of MMyy for the FullDateTimePattern property.
Technorati Tags: System.DateTime.ParseExact,C# -
osql.exe and unicode files – how to save your sql scripts with encoding
osql.exe is a great application for running sql scripts in a batch. I use a batch file to execute multiple sql scripts that I use to rebuild my current application database from scratch. When developing a brand new application, deploying a database in this way makes it really easy to recreate the database just like it will be created on Day 1 when you build out the Production environment. This requires scripting out all of your sql objects and then also having a way to execute all of those sql scripts easily. That is where osql.exe comes in handy.
But osql.exe does have one issue that I ran into this week where it does not like UTF-8 (codepage 65001) or UTF-7 (codepage 65000) encoded files. And sometimes you need to include unicode characters in your sql scripts. At first I thought osql just did not support unicode but that is not the case… it just does not like the UTF-8 or UTF-7 encoding.
Trying to run a UTF-8 (codepage 65001) or UTF-7 (codepage 65000) encoded file with osql.exe will give you errors such as:
Incorrect syntax near '+'.
Incorrect syntax near ' '.
Incorrect syntax near 'ï'.Saving the same file with Unicode Encoding (codepage 1200) will work just fine. Here is how to save sql scripts in Microsoft SQL Server Management Studio with a particular encoding (you can also use this method to see what type of encoding the file is saved in in the first place). One other thing to note is that Visual Studio has this same type of Save As… functionality.
From the Microsoft SQL Server Management Studio (or Visual Studio) File menu choose Save [FILENAME] As…
Then when the Save File As dialog appears you will see a little black arrow (inverted triangle) as part of the Save button.
Clicking the just the inverted triangle portion of the button will give you a menu.
Choosing the Save with Encoding… option will then present you with an Advanced Save Options dialog.
Here is where you can specify the encoding to use for the file. For osql.exe make sure you specify either Western European (Windows) – Codepage 1252 or Unicode – Codepage 1200. Do not select UTF-8 (codepage 65001) or UTF-7 (codepage 65000) or osql.exe will give errors when trying to parse the file.
-
Asynchronously sending a System.Net.Mail.MailMessage in C#
When sending an email in your ASP.NET application there are times when you do not want the user experience to slow just to wait for an email to be sent. The code sample below is how to send a System.Net.Mail.MailMessage asynchronously so that the current thread can continue while a secondary thread sends the email.
public static void SendEmail(System.Net.Mail.MailMessage m)
{
SendEmail(m, true);
}public static void SendEmail(System.Net.Mail.MailMessage m, Boolean Async)
{System.Net.Mail.SmtpClient smtpClient = null;
smtpClient = new System.Net.Mail.SmtpClient("localhost");
if (Async)
{
SendEmailDelegate sd = new SendEmailDelegate(smtpClient.Send);
AsyncCallback cb = new AsyncCallback(SendEmailResponse);
sd.BeginInvoke(m, cb, sd);
}
else
{
smtpClient.Send(m);
}
}private delegate void SendEmailDelegate(System.Net.Mail.MailMessage m);
private static void SendEmailResponse(IAsyncResult ar)
{
SendEmailDelegate sd = (SendEmailDelegate)(ar.AsyncState);sd.EndInvoke(ar);
}To use this just call the SendEmail() method with System.Net.Mail.MailMessage object.
-
How to disable an ASP.NET button when clicked
Scenario: user clicks a button in your ASP.NET page and you want to disable it immediately using javascript so that the user cannot accidentally click it again.
Originally I thought this was going to be simple by using the onclientclick property of the ASP.NET button server control but although that worked to disable the button, it did not continue with the form postback. Eventually after quite a bit of Googling and some more failed attempts I figured out this solution:
MyButton.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(MyButton, "").ToString());
Adding the javascript to disable the button to the onclick event by appending to the Attributes collection of the ASP.NET button control but then also calling the Post Back Event Reference for the button right after disabling the button. That is why my original try at adding the javascript failed, adding the this.disabled=true to the onclientclick event then overwrote the call to the post back event.
With the code above now the button onclick event will look something like this:
onclick="this.disabled=true;__doPostBack('MyContrl$MyButton','');"
The button is disabled AND then the button post back method is called.
-
How to programmatically connect to QuickBooks Online Edition (QBOE)
Here are all the steps to connect to QuickBooks Online Edition (QBOE) and retrieve some data. Special thanks to Keith Palmer for his comments, answers, and his Consolibyte Solutions Website which really helped me get this working. Originally posted on StackOverflow: Connecting an ASP.NET application to QuickBooks Online Edition.
- Register your application at http://appreg.quickbooks.com. This will give you your App ID and Application Name. Use these settings:
- Target Application: QBOE
- Environment: Production
- Application Type: Desktop
- (using Desktop made things much easier as far as not needing certificates)
- A verification key will be sent to your email address which you need to enter on page 2 of this wizard.
- Set up your QBOE Connection. Once you finish registering your application in Step 1, you will then have an Application ID. Use this ID in the url below to set up your QBOE Connection:
- https://login.quickbooks.com/j/qbn/sdkapp/confirm?serviceid=2004&appid=APP_ID
- NOTE: Make sure to replace APP_ID in the above url with the Application ID that was created when you registered your application.
- The wizard will take you through the following steps:
- Specifying a name for your connection.
- Granting Access Rights - I gave All Accounting rights since this was easiest.
- Specify Login Security - I turned Login Security Off. This is important since it makes submitting the xml to the QBOE much easier since you do not need to get a session ticket for each user.
- You will then be given a Connection Key.
- At this point you now have the 3 important pieces of information in order to gain access to your QuickBooks Online Edition (QBOE) account.
- Application Name
- Application ID
- Connection Key
- Post the XML to QBOE with the 3 pieces of access information and the actual request into your QBOE database. Here is sample c# code that will post to the QBOE gateway. This will return all customers in your QuickBooks database. Make sure to update the xml below with your Application Name, Application ID, and Connection Key.
string requestUrl = null;
requestUrl = "https://apps.quickbooks.com/j/AppGateway";HttpWebRequest WebRequestObject = null;
StreamReader sr = null;
HttpWebResponse WebResponseObject = null;
StreamWriter swr = null;try
{
WebRequestObject = (HttpWebRequest)WebRequest.Create(requestUrl);
WebRequestObject.Method = "POST";
WebRequestObject.ContentType = "application/x-qbxml";
WebRequestObject.AllowAutoRedirect = false;
string post = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<?qbxml version=""6.0""?>
<QBXML>
<SignonMsgsRq>
<SignonDesktopRq>
<ClientDateTime>%%CLIENT_DATE_TIME%%</ClientDateTime>
<ApplicationLogin>APPLICATION_LOGIN</ApplicationLogin>
<ConnectionTicket>CONNECTION_TICKET</ConnectionTicket>
<Language>English</Language>
<AppID>APP_ID</AppID>
<AppVer>1</AppVer>
</SignonDesktopRq>
</SignonMsgsRq>
<QBXMLMsgsRq onError=""continueOnError"">
<CustomerQueryRq requestID=""2"" />
</QBXMLMsgsRq>
</QBXML>";post = post.Replace("%%CLIENT_DATE_TIME%%", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(post);
post = xmlDoc.InnerXml;
WebRequestObject.ContentLength = post.Length;
swr = new StreamWriter(WebRequestObject.GetRequestStream());
swr.Write(post);
swr.Close();
WebResponseObject = (HttpWebResponse)WebRequestObject.GetResponse();
sr = new StreamReader(WebResponseObject.GetResponseStream());
string Results = sr.ReadToEnd();
}
finally
{
try
{
sr.Close();
}
catch
{
}try
{
WebResponseObject.Close();
WebRequestObject.Abort();
}
catch
{
}
}- Couple things to note:
- The qbxml version needs to be 6.0 (even though the IDN Unified On-Screen Reference shows 7.0).
- The onError="continueOnError" attribute is required.
- Setting the WebRequestObject.ContentLength property is required.
- Content Type needs to be "application/x-qbxml".
- And finally I received many "The remote server returned an error: (400) Bad Request." exceptions which were not helpful at all but in the end I was able to trace them to something wrong with the xml. So if you get this exception look to your xml as the source of the problem.
Technorati Tags: QuickBooks Online Edition (QBOE) -
Version number of current application
The other day I was writing an application that posted Journal Entries to QuickBooks and I wanted to include a memo line in the Journal Entry that not only included a timestamp but also included the version number of the application that posted the Journal Entry.
To my surprise it was not very simple to do but after several failed attempts and some Googling I figured it out:
Assembly.GetExecutingAssembly().GetName().Version.ToString()
This is in the System.Reflection namespace.
Technorati Tags: Assembly Version Number -
Posting a deposit to QuickBooks Online Edition (QBOE)
When doing QuickBooks Online Edition (QBOE) development requests, you can do many tasks through the QuickBooks Online website that you cannot do through the QuickBooks SDK. Recently I ran into another one when trying to automatically insert a Deposit into a QBOE database. The DepositAddRq method is only supported in the standard QuickBooks US edition. This is the Intuit Developer Network Unified Onscreen Reference for the DepositAdd method:
Notice the US Flag icon in the implementation column. When working with QBOE you want to see the (online) icon.
This is the IDN Onscreen Reference for the JournalEntryAdd method:
Notice both the US and Online editions are both supported. And this is how we worked around not having the DepositAdd method available for our QBOE database. We just made a Journal Entry instead.
Just so you know you can also filter the IDN Onscreen Reference by the QuickBooks Edition. If you uncheck the “US” checkbox then only the methods that are available to QBOE are shown. This is nice way to filter the onscreen reference.
Technorati Tags: QuickBooks,QuickBooks Online Edition (QBOE) -
Gmail does not allow zip files with executables
I sent an email with a zip attachment the other day from my Gmail account and I received an Non-Delivery Report (NDR) from Gmail. At first I was very confused because I was purposely sending a zip file to get around any rejection of the attachment (the attachment was a C# development project that I had been working on).
This is the NDR email that I received:
From: System Administrator
Sent: Saturday, September 26, 2009 6:51 AM
Subject: Undeliverable: Emailing: project.zip
Your message did not reach some or all of the intended recipients.
Subject: Emailing: project.zip
Sent: 9/26/2009 6:51 AM
The following recipient(s) cannot be reached:
'XXXX XXXX' on 9/26/2009 6:51 AM
552 5.7.0 review our attachment guidelines.A quick Google for what was going on turned up the answer: http://mail.google.com/support/bin/answer.py?answer=9481&cbid=-16aiqkfahjlzz&src=cb&lev=answer.
Gmail does not allow you to send zip attachments with executables in them. From the Gmail FAQ:
Gmail allows you to send and receive zipped attachments, as long as they meet three conditions:
- They don't contain executable files.
- They are less than the maximum attachment size.
- They are not encrypted or password-protected AND don't contain other zipped files. If the attachment is encrypted and does not contain another zipped attachment, then it can be sent and received.
Since I was sending an entire C# application that I had been working on (I just zipped up the parent folder), the bin directory had the compiled exe in it and Gmail picked up on it and rejected the attachment.
I probably could have just removed the exe from the zip file but I tried sending as a winrar (.rar) attachment and everything worked fine. Just an FYI for anyone out there who tries the same thing but runs into the vague NDR message of "552 5.7.0 review our attachment guidelines".
Technorati Tags: Gmail Attachment Guidelines -
Awesome viral marketing video by Freebord
Check out this awesome video from freebord.com:
First time I watched this video I thought it was very cool. Then after watching it the fifth time (because I had to show it to my wife and kids) I thought: how are they skating like that? So I went to their website: http://www.freebord.com.
And then I sent the video to a couple other friends and family and tweeted it. :)
Like I said… very nice job of viral marketing.
Technorati Tags: Freebord,Viral Marketing -
Stack Overflow Profile
-
From IIS6 maxRequestLength to IIS7 maxAllowedContentLengthFile – specifying maximum file upload size
IIS6 uses the maxRequestLength config setting under the system.web section to specify maximum file upload size with a default of 4 MB. IIS7 uses the maxAllowedContentLength config setting under the system.webServer section to specify maximum file upload size with a default of 28.6 MB. This is something to watch out for when migrating your web application from IIS6 to IIS7. Read on for more information how I found out about this new config setting for IIS7….
I have migrated several sites from IIS6 to IIS7 without much problems. One gotcha that I did get caught on is the new IIS7 config settings section (system.webServer) and those settings for specifying the maximum file size to be uploaded to the website. After migrating a certain web application from IIS6 to IIS7 everything appeared fine until a few customers began complaining about issues when uploading files to the website… in particular these were large files around 50MB.
In IIS 6.0 there is a config setting (attribute) called maxRequestLength located under the httpRuntime section in system.web that you can use to specify the maximum allowed request length (in other words the maximum uploaded file size). In IIS 6.0 the default is 4096 which is number of kilobytes allowed… so a 4MB file is the default file upload size under IIS 6.0.
A 4MB is pretty small these days so it is quite common to need to override the default and put in a different value here. For the web application that I was migrating to IIS7, we had increased the maximum file size to 200MB (and told our customers 200MB was the max upload too). This is what the httpRuntime section was set to:
<system.web>
<httpRuntime maxRequestLength="204800" executionTimeout="7200"/>So we migrated the web application to IIS7, tested some large file uploads (we tested with 20MB files… note this for later) and everything seemed great. After rolling the website out to our customers, a couple weeks post release we got a couple complaints about customers not being able to upload files. Their files were about 50MB in size.
At first this was puzzling because we clearly had the config setting in place that indicated 200MB was the new limit (or so we thought) AND files larger than 4MB were allowed (we had tested 20MB files). But we could easily reproduce the customer issue with their 50MB files failing. So what was going on?
Eventually we tracked it down to IIS7 and the new config section called system.webServer. We had known that httpHandlers in IIS7 were now to be specified in the system.webServer/handlers section but what we did not know (and did not find out until our customers ran into it) was that the maximum request length setting for IIS7 is also in a new location. In IIS7 you specify the maximum size of a file to be uploaded to the website by using the maxAllowedContentLength setting (system.webServer/security/requestFiltering/requestLimits >> maxAllowedContentLength).
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="209715200" ></requestLimits>Now why didn’t our tests with 20MB files show this? Because in IIS7 the default value for the maxAllowedContentLength setting is 30000000 and that is in bytes: 30000000 bytes = 28.6 MB. So in IIS7 the default had increased to 28 MB so we did not notice it since we were testing with only 20 MB files (and assuming the default was 4MB). In the end we got this resolved fairly quickly and it showed an issue in our testing (we really should have been testing a 200MB file… the limits of what we tell our customers).
-
Credit Card Expiration Date ASP.NET MVC SelectList Sample Code
A couple weeks ago I wrote about how to create credit card expiration date drop downs for your ASP.NET application. Today I had to do the same thing but in ASP.NET MVC. For the most part I was able to use the same logic but instead of slowly building up the drop down list items, in ASP.NET MVC I created a SelectList which is constructed from an IEnumerable object containing the collection of items to display.
From the MSDN Documentation for SelectList:
SelectList Constructor (IEnumerable, String, String, Object)
Initializes a new instance of the SelectList class by using the specified items for the list, the data value field, the data text field, and a selected value.In ASP.NET MVC you can use the Html.DropDownList helper to create the dropdownlist from a SelectList object:
<%= Html.DropDownList("ExpMonth", Model.ExpMonthSelectList)%>
<%= Html.DropDownList("ExpYear", Model.ExpYearSelectList)%>But the problem is what IEnumerable object could I use to contain the month and year information but also has data value and data text parts? This is where the System.Collections.Generic.KeyValuePair structure comes in:
//Create the credit card expiration month SelectList
List<KeyValuePair<string, string>> expirationDateMonths = new List<KeyValuePair<string, string>>();
for (int i = 1; i <= 12; i++)
{
DateTime month = new DateTime(2000, i, 1);
expirationDateMonths.Add(new KeyValuePair<string, string>(month.ToString("MM"), month.ToString("MMM (M)")));
}
this.ExpMonthSelectList = new SelectList(expirationDateMonths, "key", "value", DateTime.Today.ToString("MM"));//Create the credit card expiration year SelectList (go out 12 years)
List<KeyValuePair<string, string>> expirationDateYears = new List<KeyValuePair<string, string>>();
for (int i = 0; i <= 11; i++)
{
String year = (DateTime.Today.Year + i).ToString();
expirationDateYears.Add(new KeyValuePair<string, string>(year, year));
}
this.ExpYearSelectList = new SelectList(expirationDateYears, "key", "value", DateTime.Today.Year.ToString());Technorati Tags: ASP.NET MVC,C# Sample Code -
QuickBooks Online Edition (QBOE) Testing Environment
I am developing an application that will interface with my clients QuickBooks Online Edition (QBOE) database and I need to do unit testing of this application while I am developing. The end goal of the application is to insert the appropriate journal entry items into their production QuickBooks Online Edition database, so I need to do unit testing of those inserts into a test/development QBOE environment.
There is an Intuit Development Network (IDN) testing environment which I figured was the way to go. But after several days of searching on how to get into the test environment, I eventually found out that you need to get IDN certified which costs money and also takes a good amount time.
In the end what I did was sign up for my own QuickBooks Online Edition account and created my own fake company. There is a 30-day free trial and after that it is $9.95/month. There is a good chance I will be finished with my testing before the 30 day free trial ends but even if I am not, paying $9.95/month for a development tool is perfectly acceptable in my mind too.
See this IDN thread (Is there a QuickBooks Online Edition test environment?) for a little more details on the IDN certifications if you are interested. I started this StackOverflow question too but I ended up answering my own question there (not too many StackOverflow QuickBooks users yet.)
-
Random numbers and where to get them
Ever need to randomize a list of items quickly? Then check out http://www.random.org. It can generate random numbers, lists of numbers, sequences, and much more. The one I use the most is the Random Sequence Generator. Comes in very handy when you need to randomly choose the order of a group of people.
Here is Random Sequence Generator in action. Enjoy!
-
How to Reseed a SQL Server Identity Column
In SQL Server you can specify a column as an Identity column (ColumnName int IDENTITY(1,1) NOT NULL) to have SQL Server automatically set the value of this column upon insert by incrementing a seed value. This works great but I have run into situations where I wanted to change what identity value is assigned during the next insert.
What had happened is that this table in question had the primary key column set as an Identity column. There were only a couple thousand rows in the table but SQL Server was handing out identity values in the 10-million range. In most cases this would not be a big deal, but for this table the identity value was actually used by customers so a eight digit number was not as easy to remember and repeat as a 4-digit number.
What had happened is that a row had been inserted into the table with a high identity value (over 10 million) and then SQL Server took over from there and handed out new identity values that were incremented from that number – 23000001, 23000002, 23000003, etc...
To fix this, I was able to change the seed of the Identity field by using a DBCC CHECKIDENT statement.
You can use this DBCC CHECKIDENT statement to check the current identity value:
DBCC CHECKIDENT('table_name', NORESEED)
And then you can use this DBCC CHECKIDENT statement to change the identity value to another value:
DBCC CHECKIDENT('table_name', RESEED, 2300)
After making this change new records inserted into the table now were assigned 4-digit values and were much easier for customers to remember and use.
Technorati Tags: SQL Server,SQL -
I Love StackOverflow!
Question: Should I use nvarchar(max) in place of a nvarchar(64) column or as an additional column?
First answer in 7 minutes. Completely detailed answer that thoroughly expanded my knowledge and now I feel like I have the best solution: 46 minutes. Amazing!
Technorati Tags: StackOverflow -
BabySmash! And defining what the power button does…
My son Koah loves to sit on my lap while I am working on my computer. Usually he is fine to sit and watch the screens change, windows popping up and down, browsers loading, as I did my development work. But over the past couple of weeks he has gotten much more aggressive and even having some family videos playing on the second monitor would not placate him… he just wants to bang on the keyboard.
So this is where I pulled out my old Dell 8200 laptop and installed Scott Hanselman’s BabySmash. BabySmash is an application written by Scott Hanselman that
will lock out the Windows Key, as well as Ctrl-Esc and Alt-Tab so your baby can't get out of the application. As babies smash on the keyboard, colored shapes, letters and numbers appear on the screen.
Koah loved it and had a blast as the letters and shapes appeared and disappeared as he banged on the keyboard. But Koah being a curious baby, quickly found the power button on the laptop and pressed it. The laptop shut down, no more BabySmash.
I had forgotten to disable the power button action that shuts down the computer when it is pressed. You can do this on Windows Vista under Control Panel > Power Options > Choose what the power button does. Just change the default setting of “Shut down” to “Do nothing”.
Of coarse he can still hold the power button down for 5 seconds and the entire machine will shut off... hopefully he will not be able to figure that out.
Technorati Tags: BabySmash -
StackOverflow Stickers
I got my StackOverflow, ServerFault, SuperUser, and How-To Geek stickers from Jeff Atwood yesterday (In stickers We Trust). They are really nice looking.
In case you have not heard of StackOverflow it is the most awesome question and answer site (100% free!) for developer related questions. ServerFault is for sysadmin questions and SuperUser is for general computer questions that really do not fit into the other two sites. How-To Geek is a partner of all three.
Now I have to go talk to my wife about putting these on the bumper of the car… she’s got her MOPS sticker there, so why not StackOverflow too?!?
Technorati Tags: StackOverflow -
Credit Card Expiration Date DropDownList Sample Code
The other day I needed to create a credit card input form including the drop down lists for the credit card expiration month and year. I started to write the code to populate the month and year drop down lists and I wanted to make them dynamic so that whatever the year was it would add an appropriate number of list items. But as I started thinking about how to structure the code, I figured that this has been written probably thousands of times by other developers so I would just Google for it. To my surprise, I was unable to pull back any sample code for my various search terms. In the end I had to write it myself but now I am posting it on my blog so that others my benefit from my hard work. :)
//Populate the credit card expiration month drop down
for (int i = 1; i <= 12; i++)
{
DateTime month = new DateTime(2000, i, 1);
ListItem li = new ListItem(month.ToString("MMM (M)"), month.ToString("MM"));
ExpirationDateMonthDropDown.Items.Add(li);
}
ExpirationDateMonthDropDown.Items[0].Selected = true;//Populate the credit card expiration year drop down (go out 12 years)
for (int i = 0; i <= 11; i++)
{
String year = (DateTime.Today.Year + i).ToString();
ListItem li = new ListItem(year, year);
ExpirationDateYearDropDown.Items.Add(li);
}
ExpirationDateYearDropDown.Items[0].Selected = true;Technorati Tags: C# Sample Code -
How to get the mouse wheel to work in VB6 IDE
Visual Basic 6.0 (VB6) applications are still around and frequently I will have to work on some Visual Basic 6 COM Component DLL or application. I would much rather prefer to work in c# or VB.NET but I completely understand a companies decision to not rewrite a reliable VB6 component but prefer to just make minor changes to it (especially when they have limited resources and the VB6 component does not provide value add to the customer).
So I have no problem working with Visual Basic 6 except for one of the most painful parts which is no mouse wheel support in the code window. It sounds like just a minor inconvenience but in reality not having mouse wheel support slows down development dramatically when trying to find your way around some VB6 code.
I was about to post my question on StackOverflow but as soon as I typed in my question this StackOverflow question popped up with the #1 answer pointing me to this Microsoft Support article for a Mouse Wheel Add-in for VB6:
Mouse wheel events do not work in the Visual Basic 6.0 IDE - http://support.microsoft.com/kb/837910
Follow the instructions in Method 1 described on that page and then your mouse wheel will work within the Visual Basic 6.0 IDE code window. Very, very nice!
Technorati Tags: VB6,Visual Basic 6.0 -
PureText is Pure Gold!
PureText from Steve Miller is a very simple and extremely useful utility that makes the Windows-V hot key combination paste non-formatted text instead of formatted text.
I use it all over the place and I make sure it is installed and set to run at startup on all of my machines including my wife’s laptop.
From the PureText website:
PureText is basically equivalent to opening Notepad, doing a PASTE, followed by a SELECT-ALL, and then a COPY. The benefit of PureText is performing all these actions with a single Hot-Key and having the result pasted into the current window automatically.
By the way, guess how I pasted in the text above that I copied from the PureText website? :)
Technorati Tags: PureText -
How to reset an Outlook view – expand all groups
For some reason one of my Outlook folder’s views ended in a state where the groups were always collapsed. It was not a huge deal but just annoying enough to bug me.
I tried several things to get it to stay expanded but I could not find the setting to change the view to always be expanded and stay expanded when I left the folder and returned.
Eventually I figured out that I could just reset the current view to the original settings to resolve the problem.
To do this, first browse to the folder with the view problem. Then go to View > Current View > Customize Current View…
In this dialog there will be a Reset Current View button on the bottom right. Click this button and then click OK.
Now you view will be back to the default which is to have all groups expanded.
Technorati Tags: Outlook Views,Expand All Groups -
Import RSS Feeds to New Outlook Profile from Common Feeds List
I am in the process of migrating from one Outlook profile to a new one (I am actually moving away from Exchange and back to the .pst world). Initially I created a new profile, created a data file, and then added my email account to POP email into the new data file. All done… nice and easy… time to turn off the lights and go home. Hang on a second… where are my RSS Feeds?
I use Outlook to download my RSS Feeds and I have several that I enjoy reading and now my new profile does not have those RSS Feeds listed. Luckily I was able to find two solutions to get those feeds over to me new profile.
First, I could export the feeds from my old Exchange profile as an OPML file and then import them into my new Outlook Profile. This can all be done from Outlooks File menu using the Import and Export Wizard.
This would have been easy enough but there was an even easier way for me. I added my RSS Feeds into the Common Feed List through Internet Explorer and there is an option to import the RSS Feeds from the Common Feed List.
Select this option, choose next and you will be presented with a list of RSS Feeds that you can check or uncheck for import into Outlook. Now I have my new Outlook Profile set up just like my old one when I was on Exchange.
-
BurnCDCC – Burn ISO files to DVD
One of my tools that I keep in my \Utils folders and use often is BurnCDCC. As described on the TeraByte website BurnCDCC will burn an ISO file to a CD/DVD/BD disc.
The freeware download is just a zip file containing an EXE that just runs… that’s right no install necessary. Running BurnCDCC.exe gives you a simple and easy to use user interface. Select your ISO file, check a couple of options, choose your DVD drive, and hit start… and it just works. Perfect for burning those Windows 7 and Windows Server 2008 R2 ISO images to DVD.
-
Index Server and the Enable 32-Bit Applications Setting
We had a old website that made use of Microsoft Index Server and the Index Server COM objects (ixsso,Query). Everything was working fine on our Windows Server 2003 machines under IIS6. Then when we migrated to Windows Server 2008 and IIS7 our classic asp pages (which we did a straight migration over to classic asp in IIS7) could not instantiate the Index Server objects.
Simply instantiating the object would fail:
Dim objQuery
Set objQuery = Server.CreateObject("ixsso.Query")After a call to Microsoft PSS we were finally able to track down the problem to the Application Pool running in 32-bit mode. IIS7 allows you to run the application mode in 32-bit or 64-bit by configuring this setting of the application pool:
False is the default but it was overridden to true in the Application Pool where the Index Server object was being instantiated. And the Index Server dlls are 64-bit only. So while a 32-bit dll can load in a 64-bit process the reverse is not possible. There was no reason that the application pool was set to 32-bit so we switched it to 64-bit (changed the “Enable 32-bit Applications setting to false) and everything worked.
-
Use Ctrl-m in OneNote to create a new instance
I love Microsoft OneNote and I use it so much that I want multiple OneNote instances open so that I can quickly use Alt-Tab to switch between the various notebooks, sections, and pages that I am referencing. At first I did not think it was possible to create a second instance of OneNote but then I found that Ctrl-m will create that new instance for you.
Looking under the Window menu, I see that it has been there the entire time:
Interesting that I never tried looking in the Window menu but only found out about Ctrl-m from another user. The OneNote 2007 Keyboard Shortcuts help topic also has Ctrl-m clearly listed.
I wonder if I looked in the File menu and just didn’t think to look under Window?? Or did I just not think that creating a New instance of OneNote is a Window menu function?? What did I not understand about “New Window”? Or was I looking for the New Instance menu item?? I probably will never know… but I sure am happy that I found Ctrl-m. :)
Technorati Tags: OneNote -
Use Alt-key to select arbitrary block of text in Visual Studio
One of the my most favorite tips/tricks for Visual Studio is the ability to copy and paste an arbitrary block on text in the Source View by pressing and holding the Alt-key while dragging your mouse. A quick example is the best way to describe it.
Normally you can select text line by line, starting from a point in one line of text and going to a point in another line of text and including all of the lines in between.
But if you hold down the Alt-key and drag your mouse you can select an arbitrary block of text.
And now you can use the normal copy and paste functions to grab that block of text and paste it elsewhere like so:
cation.EnableVis
cation.SetCompat
cation.Run(new FThe example above is not very practical but I have found plenty of uses for Alt-Select during my daily development work.
Technorati Tags: Visual Studio,Visual Studio Tips and Tricks -
Windows Server 2008 IIS7 SMTP properties
In Windows Server 2003 IIS6 you were able to change SMTP properties from within Internet Information Services (IIS) Manager. In Windows Server 2008 the IIS7 Manager does not handle SMTP anymore... but you can modify it by using the old IIS6 Manager which is provided as part of the Windows Server 2008 Administrative Tools.
Under Administration Tools you will now find two different IIS Manager entries. One for IIS7 and one for IIS6. Choose the IIS6 Manager to change the SMTP properties.
The IIS6 Manager will only have an item for the SMTP Virtual Server. Right-click on the SMTP Virtual Server and select properties.
This will display the familiar SMTP Properties dialog that you are used to from Windows Server 2003. Now you will be able to change things such as the size limit of the messages, the number of messages per connection, outbound delivery delay notifications, etc.
-
Visual Studio paste without changing IDs in Source View
When pasting a snippet of HTML into the Visual Studio source window, Visual Studio will automatically change the IDs to the default naming convention (TextBox1, etc.).
Most of the time though I do not want this to happen since I purposely want to have that ID copy exactly as is since it makes things easier for me when changing the name. For example, it is easier to change FirstNameTextbox to LastNameTextbox than to change TextBox1 to LastNameTextbox.
There is an option to turn the Auto ID elements on paste off. It can be found in:
Tools > Options > Text Editor > HTML> Miscellaneous > Auto ID elements on paste in Source view. Uncheck the box to turn this feature off.
Now Visual Studio will leave my IDs alone:
Michael Campbell of SQL Server Audits pointed this out to me a couple weeks ago.
Technorati Tags: Visual Studio,Visual Studio Source View -
Friendlier Windows Update in Windows 7
I recently upgraded my laptop to Windows 7 and got the new experience of the new Windows Update notification last night:
Very friendly, to the point, told me what was going to happen, and set my expectations correctly. I liked it a lot. Thank you Windows 7!
Technorati Tags: Windows 7,Windows Update -
Unexpected error encountered opening Visual Studio project
I recently tried to open a Visual Studio project that I had downloaded from Codeplex and received an error message:
Followed by this error message:
And then the Visual Studio project was not available in the solution. All the project said was “The project file cannot be loaded.” Not a very helpful error message.
This is because the project was under Team Foundation Server (TFS) source control and I do not have the TFS edition of Visual Studio. To resolve this issue open the project files in notepad and remove the source control provider lines. Usually they look like this:
<SccProjectName>XXXX</SccProjectName>
<SccLocalPath>.</SccLocalPath>
<SccAuxPath>XXXXXX</SccAuxPath>
<SccProvider>{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}</SccProvider>Remove all 4 of these lines from the project file and then save it and reopen. Now Visual Studio will not try to load TFS and you will not get the error message and the project will open correctly.
-Jeff
FULL ERROR MESSAGE TEXT:
---------------------------
Microsoft Visual Studio
---------------------------
Unexpected error encountered. It is recommended that you restart the application as soon as possible.
Error: Unspecified error
File: vsee\lib\vapifunctionwrapper\vapifunctionwrapper.cpp
Line number: 169
---------------------------
OK Cancel
---------------------------
---------------------------
Microsoft Visual Studio
---------------------------
One or more projects in the solution could not be loaded for the following reason(s):
The application for the project is not installed.
These projects will be labeled as unavailable in Solution Explorer. Expand the project node to show the reason the project could not be loaded.
---------------------------
OK Help
---------------------------
Technorati Tags: Visual Studio Team Edition,Visual Studio -
Machine Setup: Add Notepad to Send To Menu
I always customize my Send To menu to include Notepad. Having notepad in the SendTo menu allows me to easily open any file and just view the contents in notepad. Comes in handy when you do not want to load an application just to grab a config setting.
In Windows Vista (and Windows Server 2008) the Send To menu can be edited by modifying the contents of the SendTo folder which can be found here:
C:\Users\[USERNAME]\AppData\Roaming\Microsoft\Windows\SendTo
Just drop a shortcut in there to notepad:
Now whenever you right-click on a file and choose Send To you will have the option of selecting Notepad.
-Jeff
-
Why does Visual Studio not resolve my CSS class names?
Whenever I was working in Visual Studio I always found that it would not resolve the css class names in my html. The CSS Class names would appear with the green squiggly line in Visual Studio but then the page would render fine when viewing it in the browser.
Also the Design View would never show any of the css styles. But I have been working with Visual Studio since the very early days and rarely used Design View and since the CSS styles were not rendering it was just another reason not to use Design View.
I always thought it was just the way Visual Studio worked.
But recently I was trying to get intellisense to work with jQuery and I read this article by Jeff King: JScript IntelliSense FAQ.
In particular I read point #4, third bullet:
Site-Relative Paths - These are paths of the form "/folder/file", and is calculated from the base of your site (http://site/application/folder/file). This approach is supported by ASP.NET Web Forms and ASP.NET MVC. However, it is not supported by Visual Studio. The reason is because Visual Studio does not always know the final deployed location of your site and thus the path resolution cannot be guaranteed. Given that quite we've seen few folks are using site-relative paths, we could consider making an assumption just resolving this type of path to the root of the project. Given the risk that you may think your site is working when it's really not, I wanted to see how many people were supportive of this.
Notice the “[Site-Relative Paths are] NOT supported by Visual Studio”. So this was the solution to why I was not getting intellisense in my javascript. I always use site relative paths for my javascript files so I need to add this line in to get Visual Studio to find my javascript file:
<script src="/content/jquery-1.3.2.min.js" type="text/javascript"></script> <% if (false) {%> <script src="../../content/jquery-1.3.2-vsdoc.js" type="text/javascript"></script> <% } %>
So now with the “<% if (false) {%> ” Visual Studio will be able to find the javascript file which contains the intellisense information.
So now I have intellisense showing up in Visual Studio for javascript which is very nice but is not the point of this article. What I realized is that Visual Studio cannot find any files in to a Site-Relative Path which includes CSS files. So my CSS file which is referenced like this:
<link href="/content/default.css" rel="stylesheet" type="text/css" />
is not getting found by Visual Studio which now completely explains why I am getting the green squiggly lines in HTML view and why the Design View does not render as expected. Applying the same fix in for Javascript intellisense to my CSS references:
<link href="/content/default.css" rel="stylesheet" type="text/css" /> <% if (false) {%> <link href="../../content/default.css" rel="stylesheet" type="text/css" /> <% } %>
And now Visual Studio can find the CSS file and validate my CSS Class names exist (and Design View looks so much better too… I might start using it :) ):
Stack Overflow Question: Why does Visual Studio not resolve my CSS class names?
-
Machine Setup: SourceGear DiffMerge
Another tool I always have on my development machine in SourceGear’s free DiffMerge tool (http://sourcegear.com/diffmerge/)
Not only is this the diff/merge tool from Visual Studio or SourceGear Vault but it also adds some very nice and useful context menus to Windows Explorer for being able to quickly compare two files (or folders):
This comes in very handy and since it has a great price (free!) it is one of the tools that gets added to my machine at the beginning.
-Jeff
Technorati Tags: Machine Setup,SourceGear DiffMerge -
Machine Setup: OneNote Sort Pages Powertoy
I use Microsoft OneNote a lot for notes, tasks, projects, reference, etc. One of the addins that I recommend for OneNote is Daniel Escapa’s Sort Pages powertoy.
Just run the setup application that you can get from his blog, close and reopen OneNote, and you will end up with a new button in OneNote:
Clicking this will alphabetically sort the page in the current notebook. (NOTE: As Daniel mentions in his blog there is no undo and no confirmation, so be careful when hitting this button.)
-Jeff
EDIT (2011-01-25): There is now a OneNote 2010 version: http://weblogs.asp.net/jeffwids/archive/2011/01/25/machine-setup-onenote-2010-sort-pages-powertoy.aspx
Technorati Tags: OneNote -
Mindjet MindManager stops mouse from working
I recently upgraded my development machine to not only a new computer but also Windows Server 2008. I also chose to go with Windows Server 2008 64-bit to take advantage of the 8GB RAM that my new computer can handle.
The upgrade went very smoothly but over the weekend I discovered that one of my tools, MindManager 8, caused issues on my computer. Installation of MindManager was no problem and activation with my license key also was successful but when MindManager went to open the first tutorial MindMap, my mouse stopped working. I tried several different things to get my mouse functionality to work including closing MindManager and installing an updated mouse driver but nothing worked. Whenever MindManager would open a MindMap the mouse would freeze and never come back.
Today I was able to find a work around. Apparently this issue has to do with Tablet PC Input Service. Not exactly sure why but stopping and restarting the service will free up your mouse. Unfortunately you need to do this with each MindMap that you open.
- Open MindMap
- Mouse becomes frozen
- Stop/Start Tablet PC Input Service
- Mouse now works again
You can also use these commands from a command prompt window instead of the Services mmc (which really helps when your mouse is not working :D ).
net stop "tablet pc input service"
net start "tablet pc input service"UPDATE (2009-05-18): Having the Hyper-V feature enabled causes this work-around not to work. I had enabled Hyper-V and then my mouse became frozen again after opening a MindMap and stopping and starting the Tablet PC Input Service did not free up my mouse. Not sure why and I did not look into what was going on but just turned off the Hyper-V feature and my work-around above works again.
UPDATE (2009-05-22): I have found that I do not need to stop and start the Tablet PC Input Service after opening each MindMap but only at first. Right now my work-around at the beginning of each day is (yes, I shut my computer down each night :) ):
- Open MindManager (which opens the startup mind map)
- Mouse becomes frozen
- Stop/Start Tablet PC Input Service
- Mouse now works again
- Open MindMap from MindJet Connect Workspace
- Mouse becomes frozen
- Stop/Start Tablet PC Input Service
- Mouse now work again (and opening any other MindMaps will not cause my mouse to freeze)
-Jeff