Archive for August, 2008

Add Web Reference instead of Service Reference in Visual Studio 2008

I’m just in the middle turning a 2-tier app into a 3-tier app (it was planned all along, so it’s been quite easy so gar). Anyway I added the service reference to my client project and wanted to reuse shared assemblies (which was a pain in the a** in ASP.net 2.0 Webservice – let me just say I had my set of batch scripts altering the generated proxy code). But in Windows Communication Foundation it’s really easy. When you add a reference just click on the ‘Advanced’ button and choose the options.

But that’s not actually what I wanted to blog about. Even with Visual Studio 2008 and .net 3.5 (3.0) I prefer to use old style Webservices sometimes but at the same time of course I don’t want to miss out on Linq etc. Until now I kept changing the target plattform to .net 2.0 to get my ‘Add Web Reference’ context menu item and then changing it back to .net 3.5. It works, but I kept grumbling why on earth they removed the option in VS08, well it turns out they didn’t remove it, the just moved it.

In the advanced dialog at the bottom you can add a web reference as before. (But it is still counter intuitive, why is adding an old style reference a suboption after picking a service reference? I would have preferred my context menu item.)

‘MSDTC unavailable for SQL Express Transactions’ or ‘Who took my MSDTC settings on Vista?’

Greeted this morning by the following error after starting my unit tests “MSDTC on server ‘LONDON\SQLEXPRESS’ is unavailable.”. Just moved development to a new Vista machine. Ok, that’s usually solved quickly by activating Network DTC Access (side note: System.Transactions promotes to MSDTC if it needs too).

On Win2003 and XP you opened up the Component Services, right-clicked Properties on the ‘My Computer’ node under Computer Services > Computers and opened the ‘MSDTC’ tab in the dialog. There you changed the security settings. On Vista (and Win2008 where we had similar troubles a week or so ago, and I had forgotten to ask exactly where and how our sysadmin fixed it) you have to run ‘dcomcnfg’ from the run prompt and if you take the above described path it looks like this:

Lot’s of blank space and no ‘Security Settings’. Ok, in Vista onward they moved the security settings to a new node. Expand the tree to see the ‘Local DTC’ node.

Properties on that look like this:

There you can switch to the Security tab and activate Network DTC access. Voila you’re done…

Dynamic Data – GUIDs/uniqueidentifiers as primary keys

I primarily use a GUID (uniqueidentifier) as my primary key data type. You never know when you need to synchronize your data, and I’d rather be prepared by using a GUID as a unique global identifier. Anyhow, it seems that the brand new Dynamic Data (released today as part of .net 3.5 Service Pack 1) does not really support a GUID as primary key.

The Entity Framework does not pass enough meta data to the Dynamic Data. When you use DD as a simple scaffold and add a record you will be greated with a textbox to enter the primary key for your record. Not sure about you, but I don’t have a GUIDGEN method in my brain, therefore I was looking for a solution.

There some talk of adding an attribute to the column in an inherited partial class in the forum, but that isn’t an option for large numbers of tables. So I though I’d come up with a simple solution with a little help of some jQuery goodness. (I’ve been doing a lot of jQuery lately and it’s I’m really starting to enjoy Javascript!)

My idea was to allow me to create a guid via a context menu in my dynamics data project. Like this:

You can implement the solution in your app in less than 5 minutes. You need to download

Then open your dynamic data project. You need to change 2 files:

1. Open Site.Master.cs and override the OnLoad method.

public partial class Site : System.Web.UI.MasterPage
{
    protected override void OnLoad(EventArgs e)
    {
        if (Request.QueryString["genguid"] != null)
        {
            Response.Clear();
            Response.Write(Guid.NewGuid());
            Response.End();
        }
        
        base.OnLoad(e);
    }
}

2. Then go to Site.master and insert the following directly after .

<!-- Guid Fix -->
<script src="/js/jquery-1.2.6.pack.js" type="text/javascript"></script>
<script src="/js/jquery.listen-1.0.3-min.js" type="text/javascript"></script>
<script src="/js/jquery.contextmenu.r2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
<!--
    $(document).ready(function() {
        // add a sticky listener to the click 
        // event of all input elements
        $.listen('click', 'input', function() {
            // add a ctx menu to each input box that 
            // creates a guid in the textbox
            $('input').contextMenu('ctxGuid',
            { bindings: { 'createGuid': 
                function(t) { genGuid(t); } } });    
        });
    });

    function genGuid(t) {
        $.ajax({
            url: location.href,
            type: 'GET',
            data: { genguid: 1 },
            dataType: 'text',
            timeout: 10000,
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert('Error fetching guid: ' + textStatus + '/' + errorThrown);
            },
            success: function(guid) {
                $('#' + t.id).val(guid);
            }
        });
    }

-->
</script>

<div class="contextMenu" id="ctxGuid" style="display:none;">
    <ul>
        <li id="createGuid">Create GUID</li>
    </ul>
</div>
<!-- End Fix -->

Voila, you can now right-click on the primary key input textbox (or any input box for that matter) and let the server create a guid.

Hope it helps!

Entity Data Model generated from SQL 2008 and used with SQL 2005

Ok, this is of course is not a perfect scenario, because ideally my dev and test environments should be identical to my live enviroment. But anyhow, I had some troubles with Entity Framework today. After deployment my WCF services just threw exceptions (have I ever mentioned that I don’t like WCF for making everything including debugging so difficult – but that’s a different story). After I attached the debugger I finally saw what was really throwing my exceptions. It was one of my LINQ statements on the EDM, telling me:

The version of SQL Server in use does not support datatype ‘datetime2′.

Funny, I thought. Since I don’t use datetime2. It’s actually just a model imported from a SQL 2005 database to SQL 2008. But since I had generated it again from the SQL 2008 (or was it just an update, I can’t remember) it must have remembered this fact and now maps the datetime differently?

The solution in case anyone has the same problem is to open your EDMX in a file editor (or “open with…” in Visual Studio and select XML Editor). At the top you will find the storage model and it has an attribute ProviderManifestToken. This has should have the value 2008. Change that to 2005, recompile and everything works.

Hope it helps.

Sync Framework is now RTM – Go check it out!

It has finally arrived. Sync Framework as of now is live and available for download at http://www.microsoft.com/sync. Check out the release post or download it directly here. This is great and gives me a really good reason to post some more. I hardly posted anything about the last pre-release but in August check back soon for some interesting stuff.

Until then go download the bits, start playing, check my past articles in this section – the basics certainly apply, but I’ll update them to RTM status as soon as possible.

For all those in and around Vienna the ANUGA will be restarting the user group season with a special Sync Framework event on August 28th, so be sure to check the website.

Let’s keep the world in sync (how dramatic!).

Windows Server 2008 Terminal Server connections beep

Anybody else encounter the problem that when connected to a Windows 2008 server via MSTSC (Remote Desktop/Terminal Services) any dialog box causes your local machine to beep? I didn’t help to switch off sound in the MSTSC settings or anything. It not only drove me crazy but I’m sure my office colleagues will agree a fix was way overdue.

The quick way, just run “net stop beep” on your LOCAL machine (not the server).

This technet article explains the way to disable it permanently.

“SQL Server 2008 Agent will not accept DatabaseMail (bug in feb ctp?)” or “How to activate DatabaseMail using stored procedures/regedit”

I wanted to set up some error notification for a SQL Server Agent job this morning on our SQL Server 2008 (February CTP 10.0.1300) installation. It’s fairly straight forward. First you set up database mail using the configuration wizard. Next you set up your operators. Now comes the interesting part that I had to troubleshoot.

In SSMS (SQL Server Management Studio) open the properties tab of the SQL Server-Agent. There you will find what is most probably called “Notification system” or “Warning system” (I’m sorry for that. Somebody installed a German server *doh* Why are servers translated? Come on, it’s not necessary if you ask me). Activate the mail profile checkbox, select datbase mail as the mail system and then the profile you just selected. Ok the dialog. Then right-click on the agent again and restart it. Re-open the properties dialog and you may find that the mail system has jumped back to SQLMail. If not, continue reading below, maybe you are running a version were this was fixed. However I tried generating a script to see what the dialog is doing behind the scenes when I activate database mail. (By the way, one of my favorite features in the newer Microsoft tools!).

The script read:


USE [msdb]
GO
EXEC msdb.dbo.sp_set_sqlagent_properties @email_profile=N'Default'
GO

This sounded a bit strange, because there was no reference to the actual activation of database mail. Only the profile was set. Thanks to this TechNet article I found the commands required to activate database mail.


EXEC master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'UseDatabaseMail', N'REG_DWORD', 1

EXEC master.dbo.xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'DatabaseMailProfile', N'REG_SZ', N'Default'

Execute that (or make the changes in regedit yourself), restart the sql server agent and voila database mail is activated.

Next up is the easy part. On your job properties (right-click ont he right job under jobs in the SQL Server Agent) you have the tab “Notifications”. Here you activate E-Mail, select an operator, select the cause and you are ready to go. For testing I would recommend selecting ‘At the end of a run’ (again, sorry for a possible wrong translation) and then run the job.


Subscribe / Search


XING

 

August 2008
M T W T F S S
« Jul   Jan »
 123
45678910
11121314151617
18192021222324
25262728293031

Twitter

Blog Stats

  • 356,722 hits

Follow

Get every new post delivered to your Inbox.

Join 57 other followers