Unit test issue since upgrade
We had an Visual Studio 2005 solution with a number of test projects, this is a database project, that has 2 SQL 2005 Express databases. In the tests, these databases are copied to the test result folder, and are attached and used for the unit tests.
We have just upgraded the solution to Visual Studio 2008, and now the unit tests do not work. At first there was an error that was related to the reference to version 8 of the unit testing references (Microsoft.VisualStudio.QualityTools.UnitTestFramework), but now I have an issue with the database being attached.
This is the error message I now get.
"An attempt to attach an auto-named database for file C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\TestCompositionDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
This is the connection string used.
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TestDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" />
Has anyone else had this issue, or have a solution. I searched for this error message online, but have found a number of old posts on issues with asp websites, and the user instance property in the connection string. Removing this has no effect.
Thanks
Clint Colefax
Edit: I think this has something to do with the DataDirectory placeholder, when I manually copy the database files to the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ folder, it works fine. Does anyone know if the DataDirectoy macro has changed in 2008 and what I would need to do to fix?
Edit Edit: I tried setting the DataDirectory value manually before the database attach by using AppDomain.CurrentDomain.SetData("DataDirectoy", testContext.TextDeploymentDir) and it then works (testContext.TextDeploymentDir is the location the applications is copied to for testing). Before settings this, the value is nothing. Has something change from 2005 to 2008 to stop this from being populated automatically. Do I now need to manually set this in the ClassInitialize in each test, and how will this then effect the deployed application?
Answers
Clint, this is a known issue. Your workaround to change the data directory is the one I would recommend. The root cause of that issue is that, for perf improvements, we changed application base directory of the app domain used for unit tests to be Common7\IDE under Visual Studio installation instead of test deployment "Out" directory, and one of the implications of that is if you use |DataDirectory| (which resolves to the application base, not to the current directory), the CLR will look for your database in the Common7\IDE, not in the test deployment "Out" directory.
Another workaround is to specify full path to the database file. We are going to fix this issue in Visual Studio SP1.
Thanks,
Michael Koltachev, Visual Studio Team Test
All Replies
Clint, this is a known issue. Your workaround to change the data directory is the one I would recommend. The root cause of that issue is that, for perf improvements, we changed application base directory of the app domain used for unit tests to be Common7\IDE under Visual Studio installation instead of test deployment "Out" directory, and one of the implications of that is if you use |DataDirectory| (which resolves to the application base, not to the current directory), the CLR will look for your database in the Common7\IDE, not in the test deployment "Out" directory.
Another workaround is to specify full path to the database file. We are going to fix this issue in Visual Studio SP1.
Thanks,
Michael Koltachev, Visual Studio Team Test
Thanks for the Response Michael, I will set the value in our tests.
Thanks
Clint Colefax
- Michael,
We too have run into this problem. However we are unable to use the workaround specified in a prior entry. Is it is due to the fact that we are using CSV data and the connection string has no DataDirectory macro? We tried using different paths for Data Source to no avail.
Here is the original connection string which worked for us in VS2005:
<add name="CSVFileDataConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=.;Extended
Properties="text;HDR=Yes;FMT=Delimited""
providerName="System.Data.OleDb" />
Obviously that one will not work in VS2008 due to the bug you acknowledged. So...we tried some variants on the Data Source value in order to get a literal path to work. None of them worked. We made sure the files did exist in each specified directory but we keep getting the following error returned from the runtime: "syntax error in FROM clause" Perhaps we have an incorrect syntax? If not, then we do not have a workaround and this becomes a showstopper issue for us.
Some variants we tried:
<add name="CSVFileDataConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source="C:\\UnitTestData\\";Extended Properties="text;HDR=Yes;FMT=Delimited""
providerName="System.Data.OleDb" />
<add name="CSVFileDataConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
DataSource=C:\\UnitTestData\\;Extended Properties="text;HDR=Yes;FMT=Delimited""
providerName="System.Data.OleDb" />
<add name="CSVFileDataConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\UnitTestData\;Extended Properties="text;HDR=Yes;FMT=Delimited""
providerName="System.Data.OleDb" />
<add name="CSVFileDataConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\UnitTestData;Extended Properties="text;HDR=Yes;FMT=Delimited""
providerName="System.Data.OleDb" />
thoughts/comments?
thanks,
steve Steve,
We got the same problem. Surprisingly we found that in the app.config ,after changing the datatablename value from filename.csv to filename#csv, the problem was solved. Hope this helps you out.
<
microsoft.visualstudio.testtools>
dataSources><
<
add name="DataItemABC" connectionString="DataItemXYZ" dataTableName="FileName#csv" dataAccessMethod="Sequential" /></
dataSources></
microsoft.visualstudio.testtools>Cheers
Saurabh
- Hi Michael,
I faced this problem now, and I need to change directory from C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
to directory with my test,
do you know how can I do it?
Thanks and Regards,
Alexander. - Does any one know when is this going to be fixed .
Vs 2008 SP1 doesnt seem to have a fix.
This is a similar bug which i have raised.
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=415460&wa=wsignin1.0
Y2KPRABU, MCTS,MCPD INDIA


