views:

83

answers:

0

My program has been working for a long time. After trying to use SMO in my program to do a database restore I can no longer attach my database to my named instance. I keep getting the following:

"Cannot open user default database. Login failed.\r\nLogin failed for user ...".

At first I could not attach to it in Management Studio either. I was getting this error:

"Cannot attach a database that was being restored. (.Net SqlClient Data Provider)"

I was able to find a fix for the above (I created a new database with the same name, took it offline, and replaced the newly created file with my old file). Doing this allowed me to attach it in Server Management Studio, but I still could not connect to my database in my program.

I then renamed my database file, changed my connection string accordingly and then I was able to connect in my program. Can someone direct me on what I need to do to allow me to use my original filename again? It's as if SQL Server has blacklisted my file or the username in my connection string from accessing that file.