Cannot attach database after update

I have a VB.net app that I have developed over the years that uses a SQL database that I have developed along with it. My problem arose a couple of months ago when I installed an update to MSSQL. The program no longer would attach to the database, and I get the following error message:

[Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click the application will quit immediately.

Cannot open database “D:\DATAFILES 092015\DVD_LIST.MDF” requested by the login. The login failed

Login failed for user ‘DESKTOP-H7RL6S9\Darby’]

While trying to figure out what happened I noticed when I opened SQL that the Server Name comes up as SQLEXPRESS06. I am pretty sure the original coding uses the Server Name as just SQLEXPRESS in the open database command line. I also discovered that I have SQLEXPRESS01 through SQLEXPRESS06 and have no idea where they came from. The only app I have that accesses a database is the original one I developed.

How do I fix this problem and enable my app to attach to the database. Can I change all the filenames with the 06 suffix to just SQLEXPRESS? Also is it necessary to keep all the SQLEXPRESS01-06 instances or can I delete them once my problem is solved

darby

Are you able to connect when using SQLEXPRESS in the server name?
Go to SQL Server configuration manager on the machine and see if your see multiple SQL services running there.

I am not able to connect to my database using SQLEXPRESS, only SQLEXPRESS06. In checking SQL server configuration manager, only SQLEXPRESS and SQLEXPRESS06 are running.

What do you see in the SQL error log in SQL server management studio related to login failures or particular to that database in issue?
The login failure message that you posted normally tells the database name to which your application is not able to connect. Something like below:

**Cannot open database "DatabaseName" requested by the login. The login failed. **
Login failed for user 'DESKTOP-TEST\User'.

Verify the application connection strings.

As stated in the original post;

Cannot open database “D:\DATAFILES 092015\DVD_LIST.MDF” requested by the login. The login failed

Login failed for user ‘DESKTOP-H7RL6S9\Darby’

connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename="D:\Data Files 092015\DVD_List.mdf";Integrated Security=True;Connect Timeout=30"

Can you try this?
Using database name instead of AttachDbFilename parameter.

connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Database=DatabaseName;Integrated Security=True;Connect Timeout=30"

I get the same exception error.

Hi

Hope this helps

Solution

1. Update Your Connection String

The most immediate fix is to update your VB.NET application's connection string to use the correct SQL Server instance name (SQLEXPRESS06 instead of SQLEXPRESS).

Here’s how to modify your connection string:

vbnet

' Original connection string  
Dim connectionString As String = "Server=SQLEXPRESS;Database=DVD_LIST;User Id=DESKTOP-H7RL6S9\Darby;"  

' Updated connection string  
Dim connectionString As String = "Server=SQLEXPRESS06;Database=DVD_LIST;User Id=DESKTOP-H7RL6S9\Darby;"  

If you're using a connection string in a configuration file (e.g., app.config), update it there as well.


2. Verify SQL Server Instance

Ensure that SQLEXPRESS06 is running and properly configured:

  1. Open SQL Server Management Studio (SSMS).
  2. In the "Connect to Server" dialog, verify that the server name is SQLEXPRESS06.
  3. If it’s not running, start the instance.

3. Check Database File Permissions

Ensure that the user account (DESKTOP-H7RL6S9\Darby) has the necessary permissions to access the database file (DVD_LIST.MDF):

  1. Right-click the database file (D:\DATAFILES 092015\DVD_LIST.MDF) and go to Properties.
  2. Ensure that your user account has Read/Write permissions.

4. Detach and Reattach the Database

If the database is not already attached to the SQL Server instance, you may need to attach it:

  1. In SSMS, right-click Databases and select Attach.
  2. Browse to your database file (DVD_LIST.MDF) and attach it.

5. Manage SQL Server Instances

You can keep only the instance you need (SQLEXPRESS06) and uninstall the others:

  1. Open Control Panel > Programs and Features.
  2. Uninstall any unnecessary SQL Server instances (e.g., SQLEXPRESS01 through SQLEXPRESS05).
  3. Ensure that SQLEXPRESS06 is fully functional and retains your database.

Final Notes

  • Connection String: Always use the correct SQL Server instance name in your connection string.
  • Database Permissions: Ensure the user account has proper permissions to access the database file.
  • SQL Instances: You only need one SQL Server instance for your application. Uninstalling the others will clean up your system.

If you continue to encounter issues, verify that the database file is not being used by another application or instance. Let me know if you need further assistance!

The only place I find the connection string mentioned is in the app.config file and the MySettings file, which I think were automatically generated, and it looks like this:

<add name="TestMovies.My.MySettings.DVD_ListConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Database=D:\DATAFILES 092015\DVD_LIST.MDF;Integrated Security=True;Connect Timeout=30"

I am 99% sure I originally coded it as your 'original' statement
ie: Dim connectionstring As String " "Server=SQLEXPRESS; Database=DVD_List;User Id=DESKTOP-H7RL6S9\Darby;"

but I don't find that anywhere.
I am 81 years old and I've been working on this app since 2007, so my mind is cloudy at best on some of the original coding. The problem is I have added more movies to the collection, and I have no way of adding them to the database. As I said I'm 81 and the database contains information on 1200+ movies and I really can't keep them all in my head.
HELP PLEASE I' LOST

darby