Skip to main content

Posts

Showing posts from 2009

MySQL Connector - Error with Multiple Versions on Dev Machine - "...column 'InvariantName' is constrained to be unique..."

I installed another version of the MySQL connector on my development machine yesterday, parallel to my existing version - so I now have both 5.0.6 and 5.07 installed. I use these two different versions of it for a couple of different applications I work with. Now however I find that I’m unable to open EDMX files in projects using Entity Framework. I get the following error when I double click on the designer file:



Looking at the machine.config file, I can see there are 2 entries in there for MySQL and sure enough, the invariant names are the same:



<DbProviderFactories>
...
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.0.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=&quo…

The potential PROs and CONs of using ASP.NET MVC 1.0 for your next web project...

PROS:

Properly testable and allows you to develop more elegant code.You are ‘forced’ to apply the MVC design pattern by the framework, so the only option is to have a properly defined data model + business logic layer (Model), presentation layer (View) and controller to manage their interaction.You also don’t have to deal with the ASPX page lifecycle.Because ASP.NET MVC is RESTful also, it can be used easily with jQuery/JSON, etc - the way the application is organised is more like a RESTful service. The ‘Views’ are like enhanced transforms, layered across the top of the service, that convert the dynamic application output into HTML (if that’s how you choose to define your View), rather than a series of concrete ‘pages’.Because of the way the URLs are put together (i.e. you mostly don’t need to use a suffix - like .aspx - especially under IIS7), the style is better aligned for web search engine optimisation. Web design is much easier - if you get a nice HTML page from a designer, it’s m…

SQL Server - database mail - just “because you can”, doesn’t make it right!!

Was thinking the other day (discussing across the office with a couple of colleagues actually ;-) about using database mail out of SQL Server in relation to using .NET components to send mail – kind of a hot topic for us, or at least one that's heating up.My opinion on this type of thing (thankfully shared by our DBA) is that despite the fact that SQL Server provides a very adequate email platform, and there are lots of MSDN type examples out there showing you how do this type of thing, sending bulk email from the database server (for – e.g. – an email marketing campaign type stuff) is bad form.For one thing you're putting unnecessary load on the server and slowing down applications that are using the server for doing what it's designed to do (manage and serve up relational data), and for another thing – there is simply much better support for doing this type of thing outside of the database, in application code.Here's my analogy; say you want to do some work on your c…

Using ASP.NET MVC 1.0 with Dynamic Data...

Getting Started:
Dynamic data is part of 3.5 SP1, but if you want to use MVC you need to specify that the DLLs should be copied to your \bin folder:



Setting “Copy Local” to True for the highlighted DLLs will copy them to the output folder automatically when you build and publish. Makes a bin-deploy of the MVC project easier.

...And Then:
Read Scott Hanselman's talk about MVC and DD sites together: http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx
Then, go to this site: http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=14473
...and get this sample: http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=14473#DownloadId=37136
You need to reference system.web.dynamicdata: http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.aspx
Here's what needs to be done to enable configuration of DD for a new site: http://blogs.msdn.com/scothu/archive/2008/06/23/how-to-add-dynamic-data-to-an-existing-web-site.aspx
Ne…

Web.Config Inheritence to Virtual Directory Application - 'inheritInChildApplications' Attribute...

Had a problem recently where an ASP.NET MVC 1.0 site was not reading the web.config in the virtual directory that we has created for it (using Helm). It was defaulting back to the main site's web.config file (in the wwwroot directorty). The error message we got was like this:
============================================================
Server Error in '/blah' Application.
Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 
Parser Error Message: Could not load file or assembly 'MagicAjax' or one of its dependencies. The system cannot find the file specified. (<path_to_folder>\wwwroot\web.config line 133)
============================================================
...so, (FYI, this has nothing to do with MagicAjax, just using this error as an example of the type of problem that can crop up) th…

Dynamically Alter a PDF in ASP.NET Using iTextSharp...

Here's a class/method that can be used to generate a PDF order form on the fly, on your website.
It's only really applicable in the current state if you had a site that was selling a single product at a time, but this provides a proof-of-concept which you could extend/evolve to do more-or-less whatever you want, within reason. You wouldn't want to be (re)generating the PDF each time an order was placed for example, but it could be useful if you had a fax order form for a product(s) and their price(s) needed to be changed by (e.g.) 10%:

using System; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf;
namespace YourProject.Utils { public class PDFGeneration { public static void RegenerateFaxOrderForm( string title, string rrp, string price) { // get the filename #if DEBUG string fileNameFaxOrderForm = @"\Content\Images\FaxOrderForm\FaxOrderForm.pdf"; string…

Using jQuery to make HTTP GET requests for JSON functions in ASP.NET MVC ...

Doesn't work for IE...because IE caches the results of the $.getJSON(...) HTTP GET query and you end up with the appearance of the same response every time
For example, I was writing some code that required a countdown this-evening and everytime I refreshed my IE window, I was starting from the same place I sarted before - e.g. if there were 32 minutes 7 seconds remaining on the counter, the counter counts down 10 seconds and you refresh the browser, you end up back at 32 minutes 7 seconds...frustrating, cause (of course) the problem only occurs in IE!
Way to solve it is the use a POST request. Go into your jquery-1.3.2.js file (or whatever version you're using), and find the getJSON method that you're using the make the GET request. Underneath that, paste in the following code:
postJSON: function(url, data, callback) {     return jQuery.post(url, data, callback, "json"); },
...then simply change the javascript methodcall you're making to postJSON instead of get…

How to Prevent Debugger Step-Thru Spontaneously Dying in IIS 7.0 ...

This frustrated me for a while until I Googled it and discovered it’s a preventable thing.
I guess there’s a good reason for it (somewhere), but when your stepping through debugging your ASP.NET website and just getting to the bottom of an issue when the debugger quits saying that the web server was unresponsive for 59.999 seconds, it can get on your nerves ;-) Here’s how to prevent that from happening…
Go to the application pool for the app you’re debugging and check out the ‘Advanced Settings’:

… set ‘Ping Enabled’ to false and you will find you can leave your debugger hanging as long as you like (again) while you dig through stuff…

ASP.NET MVC + Dynamic Data ... <tagMapping /> and App_Code folder

If I have a <tagMapping /> config file entry associated with a class in the App_Code folder, I seem to get the following error message without fail, at runtime:
Parser Error Message: The type 'MyNamespace.CustomDynamicValidator' is ambiguous: it could come from assembly 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\50512c51\4b64a02d\App_Code._ejsf967.DLL' or from assembly 'C:\WebApps\MyApp\ MyApp\bin\MyAssembly.DLL'. Please specify the assembly explicitly in the type name.
No biggie, just kind of a PITA actually. Now I need to put any code I'm using <tagMapping /> with in the root directory, and then it works fine.

ASP.NET MVC v1.0 - Generic Html.ActionLink(...)

... was removed for release of version 1.0.
This has been documented in about a million other places, but not many posts reference where to get the 'ASP.NET MVC v1.0 Futures' DLL (as opposed to the BETA Futures).
It's here:
http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=aspnet&DownloadId=61773&FileTime=128813720881730000&Build=15036

You need this DLL if you want to use the generic version of the ActionLink - which can be used like this:
==================================================================
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> <%@ Import Namespace="Bernard.Controllers"%> <%@ Import Namespace="Microsoft.Web.Mvc"%>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Index </asp:Content>
<asp:Content ID="Con…

My First Lambda Expression ...

Instead of using the following code to bypass an invalid site certificate for the HTTPS web-service I'm using:

System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CertificateValidation);
...
private bool CertificateValidation(
            Object sender,
            X509Certificate cert,
            X509Chain chain,
            SslPolicyErrors Errors)
        {
            return true;
        }

You can use a lambda expression to do the same thing - like this:

System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, Errors) => true);

Sweet ;-)

The SDLC ...

Creating New User in SQL Server 2K5 and 2K8

Basically the GUI doesn't work properly - so just script it! Like this:

CREATE USER [NT AUTHORITY\NETWORK SERVICE]
FOR LOGIN [NT AUTHORITY\NETWORK SERVICE]
WITH DEFAULT_SCHEMA=[your_schema]
GO

The problem is when you want to assign a default Schema to your User - it just won't do it. You select 'your_schema', and hit 'Ok':



... only to find that your queries don't run as expected and when you go back into the settings GUI, the default Schema has gone back to 'dbo'. Grrrr ...

Building SOAP Web-Service Clients in .NET 2.0 - Notes To Self ...

This post is a few notes to help me next time I come across issues building a web-service client ...

Some often used code snippets:

For completeness, init the client proxy:

If you are using WSE: ServiceWse svc = new ServiceWse();

Else:Service svc = new Service();

Set the web-proxy to null, so as to bypass a firewall:

svc.Proxy = new System.Net.WebProxy();

Set the version of SOAP - by default .NET uses 1.1 - incase you need another version, you can do this:

svc.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;

Code to use if your client needs to use UsernameToken authentication (WSE 3.0):

Microsoft.Web.Services3.Security.Tokens.UsernameToken usrToken = new Microsoft.Web.Services3.Security.Tokens.UsernameToken("UID", "PW", Microsoft.Web.Services3.Security.Tokens.PasswordOption.SendHashed);svc.RequestSoapContext.Security.Tokens.Add(usrToken);

Code to use if you need to bypass an invalid certificate:

System.Net.ServicePointManager.ServerCertificateValidationC…