Solved

Cannot Open .mdf Database in Windows Application

Posted on 2016-07-27
7
30 Views
Last Modified: 2016-08-08
I have a Windows application (Visual Studio 2013) with an .mdf database. If I am in the VS development environment, I can open the .mdf file without problems but when I run the application with F5, I get the attached error message. On the pc is also SQL Server 2016 Management Studio installed. As far as I can see from Google, the problem is that SQL Server does not permit remote access. Is this right? If yes, how do I do to allow remote access?

Thanks in advance!


Best regards
Kim Neesgaard
Denamrk
0
Comment
Question by:Kim Neesgaard
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:funwithdotnet
Comment Utility
A .mdf connection is almost always local. No remote access needed.

To answer your question, if you want to enable remote access for SQL Server, run the SQL Server Configuration Manager and configure & enable the desired protocol under SQL Server Network Configuration. The TCP/IP default port is 1433. Also check that the desired protocol is enabled under SQL Native Client [version #] Configuration.   The firewall on both ends of a connection will need to allow the specified port.

You might try building your application and running the .exe without debugging. It might offer a clue as to the issue.

Good luck!
0
 
LVL 6

Expert Comment

by:Manju
Comment Utility
attached error message?
0
 

Author Comment

by:Kim Neesgaard
Comment Utility
Error messages is now attached.
EE-SQL.png
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:funwithdotnet
Comment Utility
Error 26 is the common "can't find server" error.

You can look at this link to begin troubleshooting the issue.

You can also post your connection string (don't compromise security) so we can look for some obvious error. Also, if you show us how you are using the connection, it might help.
0
 

Author Comment

by:Kim Neesgaard
Comment Utility
-> funwithdotnet:
Your remark 'A .mdf connection is almost always local. No remote access needed.' is according to my experience with the same application on my previous pc where I ran Visual Studio 2010 (and SQL Server 2008 Management Studio) - here there was no problems to connect.

I used two connectionstrings (I have renamed database and folders):

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\2. Kims data - applikationsudvikling\WinApp\foldername1\foldername\db.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"

And this if I would connect to the .mdf in the same folder a the .exe:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\2. Kims data - applikationsudvikling\WinApp\foldername1\foldername2\db.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"
0
 

Accepted Solution

by:
Kim Neesgaard earned 0 total points
Comment Utility
The solution to this is pretty simple: for some reason an SQL Server was not installed together with the Visual Studio 2013 installation (which I think was the case for earlier versions of VS). Installation of SQL Server 2016 Express completely solved the problem.
0
 

Author Closing Comment

by:Kim Neesgaard
Comment Utility
It solved the problem and was suggested as solution on a Danish IT forum.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

771 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

14 Experts available now in Live!

Get 1:1 Help Now