0

I build an application using EF6 for query data.
When I execute the application on my computer, it runs as expected but on other computer I've got the error message
enter image description here

I suspect, there no connection to db server, although I checked 100 times the connection string is proper and I works on my computer.

What am I doing wrong?

Cœur
  • 37,241
  • 25
  • 195
  • 267
softshipper
  • 32,463
  • 51
  • 192
  • 400
  • can you translate above error to English ? and also put the code for the connection string. – Sampath Sep 01 '16 at 05:25
  • Where is the DB server located? You are not capturing the possible exceptions your connection may throw, so I would start by doing that and showing friendly messages. That way you will know what occurred. – Andrew Sep 01 '16 at 05:25
  • DB is not on my machine, it is on a server. I think, I have to pass user and password to connect to the mssql server. – softshipper Sep 01 '16 at 05:29
  • If you use the EF in a N-tier arcitecture and don't store it in the top layer, sometimes the build doesn't include all the DLLs from EF. Make sure that the EntityFramework.SqlServer.dll is in the bin folder in your published application – Marcus Höglund Sep 01 '16 at 05:32
  • Yes, the EntityFramework.SqlServer.dll is in the folder. – softshipper Sep 01 '16 at 05:34
  • 3
    You *think* you have to pass user and password? You bet! If your connection string uses `integrated security=True`, it's using your local account and of course it won't work anywhere else. Your connection needs to have something like `User=youruser;Password=something1234`. – Andrew Sep 01 '16 at 05:43
  • @Andrew yes, you are right. `integrated security=True` do I have to set false? – softshipper Sep 01 '16 at 05:58
  • It is the right format for connection string `Data Source=Servername;Initial Catalog=DBName;Persist Security Info=True;User ID=user;Password=password;Integrated Security=False;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False` – softshipper Sep 01 '16 at 06:01
  • did you try increasing the connection timeout (Connect Timeout=15) to something like 60 ? – xwpdev Sep 01 '16 at 07:20
  • It is recommended to increase? – softshipper Sep 01 '16 at 07:50
  • It depends on your application and database. How much are you willing to wait? How long do you start considering it's **too long** and prefer to display an error? Only very very heavy queries should take longer than 15 seconds. – Andrew Sep 01 '16 at 08:10

1 Answers1

1

You have to set your current integrated security=True to false and add user and password. For example:

connectionString="Data Source=123.123.123.123;Initial Catalog=yourDBName;Integrated Security=False;User=yourUsername;Password=yourPassword"

If you leave that setting in True, user and password are ignored.

If you need more details, here you have the site regarding connection strings, in this case MS SQL Server:

https://www.connectionstrings.com/sql-server/

Now, in order to improve your application, I first suggest you capture this exceptions by using try-catch blocks, so you can display a friendly message when something unexpected occurs.

Another suggestion is that if you want to keep different connection strings for your local and the installations in other computers, you can keep your current Web.config as is and add a Web.Release.config with the modifications needed. This way, when you build your code in "Release", it will automatically have the "public" connection in its Web.config. More info about how to do this here:

https://stackoverflow.com/a/5811411/2321042

Community
  • 1
  • 1
Andrew
  • 7,602
  • 2
  • 34
  • 42