Link to home
Start Free TrialLog in
Avatar of Kim Neesgaard
Kim Neesgaard

asked on

SQL Server Connection Stops in Windows Application

Hi all!

I have a small Windows application in Visual Studio 2010 to which I have an .mdf file connected and this use to work very well. However, recently I installed SQL Server 2008 Management Studio and suddenly I could not open my .mdf file - neither from Visual Studio nor from the applcation. I get the error message 'A network-related or instance-specific error occured while establishing a connection to SQL Server etc.' I have seached google without any solution. Last time I succeded (somehow) to come to a solution by uninstalling SQL Server 2008 and - as I remember - to delete the .ldf file associated to the .mdf file.

As I want to be able to open and modify the .mdf file in my application 'production environment' i.e. not in the Visual Studio development environment, I dared install SQL Server 2008 again and exactly the same happened - the connection to my .mdf file from Visual Studio fails with the same error. Only difference this time is that I am not able to re-establish the connection between the .mdf file and Visual Studio/my application - can you please help?
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

This could be something else, but I would try the following.

When you open a file with Management Studio, the file is attached to the server. An attached database needs to be accessed through the server. This is a security feature that prevents somebody who would get a copy of the file to easily get to the data. You cannot simply copy the file or open directly as you can with files that are created in Visual Studio without a server.

In order to use it outside of the server, you need to detach it. This is simply done by right clicking on the database in Management Studio, click Tasks and then Detach.
Avatar of Kim Neesgaard
Kim Neesgaard

ASKER

Ok - when I had SQL Server 2008 installed I was able to attach it but the major problem is that I cannot open the .mdf file with Visual Studio or the application. By the way I uninstalled SQL Server 2008 as I thought it might help the problem but it did not.
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I missed your point in the first answer but this is due to my lack of knowledge of SQL Server behaviour.

I have now re-installed SQL Server 2008 the same way as earlier and restored the mdf file from my backup (yes! I am very careful about backups!!)

Does it work like when you install SQL Server 2008 all the existing mdf files are attached and if you like to work with the files in Visual Studio, you have to actively detach them with the SQL Server 2008 tool? If yes, I am in doubt about which 'Server name' to use to be able to detach the mdf file. SQL Server 2008 suggests .\SQLEXPRESS but when I try to connect, I get an error 'A network-related or instance-specific etc.' How can I get access to the mdf file in order to detach it?
I did the following:

1/ Uninstalled everythin regarding SQL Server.
2/ Uninstalled VS2010.
3/ Re-installed VS2010.

After this I could not access the .mdf file with VS2010. I found this on google:

http://social.msdn.microsoft.com/forums/vstudio/en-US/544d8efe-440d-4543-a4f2-995b9b337390/sql-server-2008-r2-express-instance-not-finding

After deletion of files in the c:\Users path, I could access the .mdf file with VS2010.

I then installed SQL Server 2008 SP3 Management Studio and did NOTHING else - no attachment/detachment. After this my .mdf-file became unaccessible with VS2010.

Again, deletion of files in the c:\Users path made the .mdf file accessible with VS2010.
I did never have this working but certainly I learned about attach/detach and this is indeed important and useful. In the meantime I have got a new pc and I have managed to make it work on this new pc. Thank you for your time!