Sunday, March 25, 2012

Can't attach to database

Hi,

I have a database that I developed using both Toad for SQL and SQL Server Managment Studio.

All was working fine. I could connect to the database with one of the above and also run two an applications I developed (one in C# and One in VB.NET using VS Express) using the standard SQLConnection class.

the following connection string worked fine...

Server="(local)"; Trusted_Connection="yes"; Database="CDEvolution";

Now, for one reason or another I decided to create a new data source in my Visual Studio project and pointed it to the database fine.

At first it seemed ok as I could see all tables from teh database. However somethign strage has happened. I now can't access the database in TOAD or SQL Server Managment Studio. I also couldn't connect using the above string.

I finally managed to get the two appllications I developed to access database using the following connection string...

Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL\Data\CDEvolution.mdf;Integrated Security=True;Connect Timeout=6000;User Instance=True;

and the applications work fine, however I can access the database using the DB tools.

In SQL Server Managment Studio I remove the database and tried to attach it again but I keep getting the following error message...

Could not find row in sysindexes for database ID 5, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes.
Could not open new database 'C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL\DATA\CDEVOLUTION.MDF'. CREATE DATABASE is aborted. (.Net SqlClient Data Provider)

Any ideas on how I can get access back?

Cheers in advance,

Kevin

The latter error looks similar to what you get if you try to attach a SQL 2005 database to a SQL 2000 instance. SQL 2000 will not work with databases that have been upgraded to SQL 2005.|||

Hi,

Thanks for the response. before all this happened I was connecting to the database using SQL Manager Studio with no problems. This all started when I created a data source connection to the database in Visual Studio Express. After that I needed to change the connection string if I wanted to connect at run time using SQLConnection and have still not been able to connect using any of the DB managment tools.

Cheers,

Kevin

|||

This error is from SQL 2000, not SQL 2005, and incidates you are trying to attach a SQL 2005 database to SQL 2000.

Could not find row in sysindexes for database ID 5, object ID 1, index ID 1. Run DBCC CHECKTABLE on sysindexes.
Could not open new database 'C:\PROGRAM FILES\MICROSOFT SQL SERVER\MSSQL\DATA\CDEVOLUTION.MDF'. CREATE DATABASE is aborted. (.Net SqlClient Data Provider)

When you attached the databaes to Visual Studio Express, it would have been upgraded to SQL 2005 format and can no longer be used by SQL 2000.

|||

Thanks,

I was under the impression that SQL Express was 2005, I will look into it further and see what I can find.

Cheers,

Kevin.

|||

Sorted!

It seems that another instance of the SQL server has been created called SQLEXPRESS and you have the option to connect to it when the application starts.

Once I connected It created a new folder called MSSQL.1 (MSSQL already exists) so I simply coppied the database files into the new folder and attached them. So now I should be able to change to application to connect at the new location and I should be good to go.

Cheers,

YNWA

Kevin.

No comments:

Post a Comment