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

asked on

Cannot Open .mdf Database in Windows Application

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
Avatar of funwithdotnet
funwithdotnet

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!
Avatar of Manju
attached error message?
Avatar of Kim Neesgaard

ASKER

Error messages is now attached.
EE-SQL.png
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.
-> 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"
ASKER CERTIFIED SOLUTION
Avatar of Kim Neesgaard
Kim Neesgaard

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
It solved the problem and was suggested as solution on a Danish IT forum.