Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not locate entry in sysdatabases for database 'mydb'

I had SQL Server 2005 on my pc and had created a few databases through it. Due to some problem, I had to reinstall it but now when i give the command "create database mydb" it says

"Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\myDb.mdf' because it already exists. Change the file path or the file name, and retry the operation."

And when i give "use mydb" command it says

Could not locate entry in sysdatabases for database 'mydb'. No entry found with that name. Make sure that the name is entered correctly.

What should I do so that it can locate my databases?

like image 425
vatspoo Avatar asked May 21 '11 13:05

vatspoo


2 Answers

I faced the same issue.

We need to use Square brackets for database name

ie

use [database]

instead of

use database

Hope it helps.

like image 134
vCillusion Avatar answered Sep 27 '22 01:09

vCillusion


You can re-attach the database files (assuming that your current installation is at at least the same service pack/patch level as you previously had it).

You can attach the database using either Management Studio, or using CREATE DATABASE

like image 39
Damien_The_Unbeliever Avatar answered Sep 24 '22 01:09

Damien_The_Unbeliever