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
DatabasesMicrosoft SQL Server

Avatar of undefined
Last Comment
Kim Neesgaard

8/22/2022 - Mon
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!
Manju

attached error message?
Kim Neesgaard

ASKER
Error messages is now attached.
EE-SQL.png
Your help has saved me hundreds of hours of internet surfing.
fblack61
funwithdotnet

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.
Kim Neesgaard

ASKER
-> 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
Kim Neesgaard

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kim Neesgaard

ASKER
It solved the problem and was suggested as solution on a Danish IT forum.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.