To Resolve error “This file is in use. Enter a new name or close the file that’s open in another program.”, while attaching a datasource in Visual Studio follow these steps:

1. Open SQL Server Management Studio
2. Expand Databases
3. Right click on database which shows the error
4. Click Properties
5. Select Options
6. Set Auto Close to True

Try attaching database in Visual Studio.