Archive

Posts Tagged ‘VB.NET’

.NET Uri, database not found, and encoding

I ran into an interesting issue when trying to debug some code a while back.  I had written a dynamic that would allow a person to authenticate and then pick a database in which to perform their operations.  For the most part, this system worked well and allowed me to keep things simple.  The part that was trick was that I had written my reporting and dashboard engine to use a single Razor .cshtml file to handle all requests.  It in turn pulled the report definition or dashboard definition XML files from the database.  The problem came when one of the SQL Server databases that the system was deployed was not the default instance but a “named instance“.

In my code, I would simply construct an Uri object and pass in the string that represented the parameters that I needed for the given page.  However, since a named instance uses the ‘\‘ character, this caused some problems as my simple string representation was not encoding the character and thus when the server received the request it was not a valid server name.  I spent hours thinking that it was a problem with the configuration with SQL Server.  It wasn’t until I debugged the .cshtml file that I realized that the name of the server was not coming across correctly and that I was not encoding the name properly.  Here is what I finally came up with to correct the issue:

string address = string.Format("../PreviewReturnSetupBillDesigner.cshtml?
Key={0}&ServerName={1}&DatabaseName={2}",
  101,
  HttpUtility.UrlEncode("monticello\test"),
  HttpUtility.UrlEncode("sample"));

Uri uri = new Uri(address, UriKind.RelativeOrAbsolute);

Previously, I was just passing in the server and database names without encoding them. This worked for all default installations of SQL Server but once you had a named instance in place, all bets were off.

Hopefully this will help anyone from spinning their wheels if they are doing anything similar…

Advertisements

Windows 8 – Cage Match – XAML vs. HTML

October 10, 2013 Leave a comment

I had a great time presenting with Brian Hitney over Windows 8 at the Charlotte ALT.NET user group this past Tuesday night.  We had some very good discussions concerning developing applications using XAML and HTML.

Here is a link to the slides.

Thanks to all who came out!

Mastering Ninject for Dependency Injection

October 2, 2013 2 comments

I am happy to announce that the book, Mastering Ninject for Dependency Injection has been published.  I worked on the project as a technical reviewer and had a lot of fun.

Mastering Ninject for Dependency Injection

If you are interest in a great reference for Dependency Injection (DI), this is a good one.  It goes deep for those of you who really want to take full advantage of a mature DI container.

I would like to thank Packt Publishing for reaching out to work on this title.

Building Immersive Windows 8 Apps

March 26, 2013 Leave a comment

I am excited to be presenting with my friend Brian Hitney tomorrow night at the Charlotte Enterprise Developers Guild.

Here is a summary of what we will be presenting:

Windows 8 opened up a whole new set of possibilities for application developers in terms of how their applications can interact with the underlying operating system, with other applications as well as with the users. Specifically this includes the ability to utilize Contracts (search, share, settings) to give the impression your application is ‘one’ with the operating system as well as creating live Tiles to allow your application to communicate with the users even when the application is not running. In this session we will take a look at how you can use Contracts and Tiles to provide your application a great user experience and make your users feel truly engaged.

Hope to see all of you there!