This documentation is archived and is not being maintained.

Troubleshooting Database Unit Testing Issues

You can configure a unit test to automatically deploy the database and generate data. If you lack sufficient permissions to generate data to the target database, you might receive an error that indicates only that you lack permissions to connect to the database.


To work around this issue, run the data generation plan manually. If you lack sufficient permissions to generate data, this approach will give you a more detailed error message that helps you to correct the problem.

If you create database unit tests for a database that contains numbered stored procedures (such as MyProcedure;2), the Create Unit Tests dialog box does not display the number designation. This behavior could result in the same procedure name appearing multiple times if you have multiple numbered versions of one or more stored procedures.

In addition, the script that is generated to test those stored procedures is missing the number designation. For example, if you generate a unit test for a procedure that is named MyProcedure;2, the script resembles the following:

EXEC @RC = [dbo].[MyProcedure]

To work around this issue, modify the generated script to add back in the number designation before you run your unit tests. If you generated unit tests for multiple numbered stored procedures, you will need to correct each test.

If you modify the App.Config file in the test project, you must rebuild the test project before those changes will take effect. These changes include those that you make to App.Config by using the Project Configuration dialog box. If you do not rebuild the test project, the changes are not applied when you run the unit tests.

If you deploy a database when you perform unit tests, the database is created by using the connection string information that is specified in your unit test configuration. The connection information that is specified in the database project build properties is not used for this task, so you can run different unit tests against different instances of the same database.

If your database unit tests are failing because of a time-out, you can increase the time-out period by updating the app.config file in your database project. The time-out on the connection string specifies how long to wait when the unit test connects to the server. The command time-out specifies how long to wait when the unit test executes the Transact-SQL (T-SQL) script.


To work around this issue, specify a larger value for the CommandTimeout attribute on the appropriate Context element in the app.config file for your test project. For example, to specify a command time-out of 120 seconds for the PrivilegedContext element, update the app.config as follows:

    <DatabaseDeployment DatabaseProjectFileName="test.dbproj" Configuration="Debug" />
    <DataGeneration DataGenerationFileName="test.dgen" ClearDatabase="true" />
    <ExecutionContext Provider="System.Data.SqlClient" ConnectionString="another connection string" />
    <PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="test" CommandTimeout=”120” />