LocalDB and NHibernate

We’ve got a request to support SQL Server 2012 in our product at work. Well, the LocalDB (coming with Visual Studio 2012; a rough equivalent of SQL Server Express of the past) is practically SQL Server 2012 I thought, so it was reasonable to do initial testing on it. We use NHibernate 3 in our system, so I went to the .nhibernate.config file, and changed the connection.connection_string property (the Data Source part of it, to be precise) from

Data Source=localhost\SQLEXPRESS

to the logically sounding

Data Source=(localdb)\Projects

and… It did not work. A bit of googling pointed me to a solution: named pipe connection. To get its name, run

sqllocaldb info <InstanceName>

in the command line, which in my case translated into sqllocaldb info Projects. The output will contain the Instance pipe name line, and the value of it is the data source name you are after. So, in my case the correct Data Source read

Data Source=np:\\.\pipe\LOCALDB#5E0F8FF8\tsql\query

(as far as I understand, usually only the number after LOCALDB# will change).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s