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
Thanks in advance!
Best regards
Kim Neesgaard
Denamrk
attached error message?
ASKER
Error messages is now attached.
EE-SQL.png
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.
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.
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;Attach DbFilename =E:\2. Kims data - applikationsudvikling\WinA pp\foldern ame1\folde rname\db.m df;Integra ted 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;Attach DbFilename =E:\2. Kims data - applikationsudvikling\WinA pp\foldern ame1\folde rname2\db. mdf;Integr ated Security=True;User Instance=True" providerName="System.Data. SqlClient"
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;Attach
And this if I would connect to the .mdf in the same folder a the .exe:
connectionString="Data Source=.\SQLEXPRESS;Attach
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It solved the problem and was suggested as solution on a Danish IT forum.
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!