Solved

SQL Server Connection Stops in Windows Application

Posted on 2014-07-27
6
40 Views
Last Modified: 2015-05-19
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?
0
Comment
Question by:Kim Neesgaard
  • 4
  • 2
6 Comments
 
LVL 40
ID: 40222784
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
 

Author Comment

by:Kim Neesgaard
ID: 40222796
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40223355
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Kim Neesgaard
ID: 40223885
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
 

Author Comment

by:Kim Neesgaard
ID: 40243009
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
 

Author Closing Comment

by:Kim Neesgaard
ID: 40785080
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now