Being a .NET developer in a Mac OSX world: connecting Mono to SQL Server


How did I get here?

I’m a long time Windows developer. Started with VB3 en FoxPro and such, and couldn’t imagine needing another plaform. Like the Mac that my geeky artistic brother-in-law loved so much. Windows was cool and I knew all about it and the Mac was for people that didn’t know how to use a PC.

The dawn of a new era

Then I came with my current employer and they provided a mobile phone and a laptop of course (like all companies in Dutch IT do). But this was about an iPhone and a MacBook Pro.
I decided to leave OSX on the machine, although I could have erased the disk and installed Windows Something, it’s got an Intel processor after all.
But leaving OSX on it, meant I had to install VMWare and run Windows and Visual Studio and such within that. And even though my machine is pretty fast, you notice the performance hit.

I kept trying, and started to like OSX and the applications on it. But what I liked most of all: hardly any updates and no reboots. I shut down my machine once a week or once every two weeks because I feel it’s something I should do. But I don’t have to: OSX keeps on running. Just close the lid, simply know that everything is suspended and know that everything will run as before when you open the lid the next day.

Amazing! I would shut down my Windows machine every night, just to make sure I had a stable system the next morning. My wife still has a Windows machine and to ensure that she makes backups every day, we configured the backup software to run “on system shutdown”. Because that is what you do every day, as a Windows user.

And then there was Mono

I’ve written about the Mono project before, albeit in the context of MonoTouch and iPhone development. Mono brings .NET to a lot of platforms, including Mac OSX. And it is really good. The Mono team is really close behind the Microsoft team in porting new API’s and Framework versions. .NET 4.0 is recently available on Windows, but Mono is already compatible.
And the amazing thing is that you can take your Windows assemblies and use them straight away on OSX! That might not be very imported for assemblies that you have the sources for, but it is very convenient for third party libraries you use, like log4net (although that has a Mono version) and Rhino Mocks.
And one of the best things the Mono team delivers is MonoDevelop: an excellent IDE for .NET development that will feel really comfortable when you come from Visual Studio.

Being a .NET developer, not necessarily a Windows developer

I still like the .NET framework, but I no longer feel that automatically implies I am a Windows developer. There are so many good tools that allow you to do everything on the Mac that you are normally doing on Windows. So I decided that in the new project I recently started (in which we will deliver on Windows) I will try to go as far as possible to develop my code on Mac OSX.
I will blog about my experiences in a series of posts. This first one is about connecting to SQL Server.

I can’t do without SQL Server

We will deliver our project an a SQL Server database, so it makes sense to use that during development also. It’s not that you have to, there are other options. If you have something like a nice Data Access Layer, you can run any SQLLite or MySql database and easily move to SQL Server later.
There also is a file-based no-install version of SQL Server these days that might run on Mono. Haven’t tried it yet, but could be promising.
But if you need SQL Server, you can still work in MonoDevelop in your comfortable Mac environment.

Inside the VM

SQL Server will run on Windows in your VM, but that will be the only thing you’ll need your VM for. SImply minimize the window after all the configuration is done and don’t think about it anymore.

Step one: opening up your Windows

You need access to your VM from your Mac, so you have to open up some things.

Go into Control Panel and choose Windows Firewall. Go to the advanced tab and add some ports. Port 1433 for SQL Server over TCP/IP and port 1434 for SQL Server over UDP. Maybe you can do without the UDP version, haven’t tried yet.

Firewall Exceptions

Step two: configure SQL Server

First, make sure the SQL browser is running.

SQL Browser

Then enable TCP/IP in the Client Protocols

Protocols

And check that the Default Port is on 1433.

Poort

In SQL Server Management Console open the properties of the server and make sure you have mixed authentication.

Mixed Authentication

Step three: connect from your code or MonoDevelop

In your connection string use the IP-address of your VMWare instance. Something like

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<connectionStrings>
		<add name="dossiers" connectionString="Server=172.16.86.128;Database=mydefaultdatabase;User ID=sa;Password=bladiebla" providerName="System.Data.SqlClient"/>
	</connectionStrings>
</configuration>

That is! You can test your connection from MonoDevelop: Go to Tools/Database/Add database connection/SQL server:
MonoDevelopDatabaseTools
Screen shot 2010-07-18 at 9.33.05 PM

, , , ,

  1. #1 door Geert om 29 juli 2010

    Bedankt voor de duidelijke uitleg, was ik naar op zoek…

  2. #2 door Daniel om 30 juli 2010

    Nice overview, can’t wait to see your next posts. One question: what GUI toolkit you intend to use on MAC OS X?cocoa# ?Winforms?

  3. #3 door Richard de Zwart om 8 augustus 2010

    Thanks Daniel, I did not yet build a real Mac OSX application using Mono, but since a couple of months you can. That means you can build a native Mac app using the Cocoa framework. The Mono team made that possible by extending the techniques they used to wrap the CocoaTouch framework for the iPhone. It is an open-source project named MonoMac and you can download it form Github (http://github.com/mono/monomac).
    On Windows I’ve always used PasswordMinder to manage my passwords, and I run that now on the Mac too. That is a standard Windows Forms application that uses the Mono Gtk libraries and,well, looks like crap (and generates tons of warnings in th ebacjground). I would like to port this to MonoMac some day. Can’t be too hard, since I can leave the business logic like it is, and just rewrite the UI. But be warned: learning the Cocao Framework requires some time. I already know the CocaoTouch Framework quite well, and was shocked to see how much more there is in the “real” Cocao Framework.

  4. #4 door danny om 3 juni 2011

    Great! It was awesome! I am able to follow all the instructions. Everything is well explained. I clearly visualize what to do. Thanks for the excellent post. It truly helps, and I will be using this for my project.

(wordt niet gepubliceerd)
  1. Nog geen trackbacks.