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?
Kim NeesgaardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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.
0
Kim NeesgaardAuthor Commented:
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.
0
Jacques Bourgeois (James Burger)PresidentCommented:
As I told you, you need to detach the file from the server in order to be able to use it directly in Visual Studio or the application. While it is attached, there is no way to use it directly. You have to go through the server, that is create a connection string that uses the server. This is a very important and very good feature of SQL Server, because it prevents data theft. Somebody who has the file without the server cannot use it. Otherwise, anybody would just have to make a copy of the .mdf to get data out of the company.

Uninstalling the server was not a good idea, because the file is still marked as attached, and you no longer have the tool necessary to detach it. You might reinstall the server on the same computer, with the same server name, and try to restore the database from a backup (you have one, isn't it? If not, you learned something). You will then be able to detach it an use it directly in Visual Studio or as a local database in your application.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Kim NeesgaardAuthor Commented:
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?
0
Kim NeesgaardAuthor Commented:
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.
0
Kim NeesgaardAuthor Commented:
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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.