Sunday, February 12, 2012

AttachDbFilename, |DataDirectory| and SQL Server 2005 June CTP Relative Paths

Hello,

I am using "AttachDbFilename" to connect to a June CTP SQLExpress database. I have a windows forms application that has the following connection string (which works fine at the moment):

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|test.mdf';Integrated Security=True;User Instance=True"

However, I would like to make my connection string:

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|..\..\Database\test.mdf';Integrated Security=True;User Instance=True"

But no matter what combination I try (including not using DataDirectory at all), I cannot seem to open the database using the relative path.

Can someone please assist/clarify?

Thanks,
Sean H.

Hi,

DataDirectory is specifically restricted to only allow access to files in the directory pointed to by the DataDirectory value or any of its subdirectories, but not directories up in the chain.

This is to prevent security issues such as those common in older web servers where you could navigate the server file-system by doing something like http://www.mywebsite.com/..\..\..\etc\passwords

-pablo|||When you say "the directory pointed to by the DataDirectory value " what exactly is that? In other words, what is this value and where can I set/change it?

Thanks - Daniel|||

you can change:

AppDomain.CurrentDomain.setData(“DataDirectory”,”C:\newPath\”);

No comments:

Post a Comment