3

I've got a web app that uses a MS SQL Server 2008 database. Recently I made two copies of the database, one for ongoing development, the other for users to begin testing and evaluting the application.

I've got two seperate web applications now. I've changed the web.config of the 'test' version to point to the test DB, but it still seems to be using the previous version.

Is this cached somewhere? I've run IISRESET on the box, but the the 'test' version of my web app still seems to point to the wrong DB.

This is driving me crazy, any help is appreciated.

3
  • No, what you said sounds right, check if there is something in your global.asax perhaps that overrides this. Commented Feb 28, 2011 at 21:24
  • 2
    Can I also make a good practice suggestion; Use SQL aliases for your Sql Servers. SO create an alias called prod, and one called test and let them point to the correct SQL Databases, and also run prod and test on different ports. SO get prod to listen on 14331 for example and test to listen on 14332. Then you can implement using the local firewall on the pc to no accept connections from the test web-server etc. That way you can segregate prod and test. In fact good practice will always tell you, prod should not be able to see de & test and vica versa. Commented Feb 28, 2011 at 21:30
  • Are you using Linq-to-SQL with a dbml file? Commented Feb 28, 2011 at 21:43

5 Answers 5

4

Just a wild guess: Your connection string might not be configured where you think it is. Either you're changing the wrong connection string, or the connection string is not being read from web.config at all.

Configuration isn't cached anywhere, so when you change the connection string and start up your application, the changed value is loaded.

What does the part your data access code which creates the DB connection look like?

Sign up to request clarification or add additional context in comments.

4 Comments

I'm using LINQ for data access. I've just checked again and my 'Initial Catalog' value in my web.config is definetely pointing to the 'test' version of the DB.
@Jimmy can you edit your post with the <connectionStrings /> section of your web.config, and the line of code which news up your DataContext?
I found the issue - my 'test' versions code was contained within the folder containing the other version, so it looks like the web.config in the directory above was being over-riding the one in the directory below - does that sound correct? I've no created the test version at the same level as the other version and it seems to work. I didn't realise web.config's worked like this - live and learn I guess.
@Jimmy - this is precisely how web.config works. You can override web.config values in subdirectories, as long as they are configured as virtual directories or separate applications in IIS, and the "baser" web.config doesn't lock the elements explicitly using the lockElements, lockAttributes etc. attributes in the configuration sections.
2

Make sure the connection string isn't anywhere else, like hibernate.config.

Comments

1

If you restored your test database from the original database and if you are using synonyms, then its possible that your synonyms' names have the full name, included the database name. Try to change these names deleting the database name from the synonyms' names!!! it will work!

Comments

0

As a complementary/additional note following the answer by @Maria, if you right-click on the restored [new] database (e.g. Test_DB), click on 'Files', and look at the 'Database Files', they may still be pointing to, for example, MAIN_DB and MAIN_DB.log. You may want to change these to, for example, TEST_DB and TEST_DB.log so your test database is actually pointing to the correct (test) data file. (However, this may only be one step out of a number of steps needed to point your test app to your test DB when you have restored your [live] database to a new [test] database.)

Comments

0

I have got the same problem. When I carefully checked my app I found out that I used two data access method. using entity framework as well as ADO.net in the same project.(I am not mush familiar with entity framework that is why I use two data access method).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.