Last post Mar 10, 2014 11:49 AM by Tomiu
Mar 06, 2014 11:11 AM|Tomiu|LINK
i have installed a Webapplication on Server 1 and the postgre database is on Server 2.
If i have the webapp and the DB on the same server than it's easy(Web.config):
<add name="ConnectionStringWeb" connectionString="Server=localhost;Port=5432;Database=postgredb;User Id=postgres;Password=$test02;SearchPath=auto,bank" providerName="Npgsql.NpgsqlConnection"/>
But how to do the same if i want to connect to a database that's on different server. Changing Server=localhost to Server=IP-For-Server-2 doesn't work.
Thanks in advance for your help
Mar 06, 2014 12:04 PM|PatriceSc|LINK
It's best to tell what is the actual error you have rather than just saying it "doesn't work" (for example here it would likely allow to know if the issue is that the web server can't access at all to the db server or if the db name is wrong or if the user
name is wrong or whatever zillions of things could happen for something that "doesn't work").
For now my best guess would be that the web server can't access the db server likely because of some firewall rule.
Mar 07, 2014 02:53 AM|Tomiu|LINK
I get the error message:
[Exception: The Connection is not open.]
If i use the database on the same Server as the Webapp it works fine.
Mar 07, 2014 03:39 AM|dyyo|LINK
based on the error message, it does not appear to be the connection string issue. but rather on your database issue (coding)
Please see http://stackoverflow.com/questions/12508873/the-connection-is-not-open for more information
Usually, if the issue is with the conn string, the error message should be something like "Server Not Found", "Cannot login to the database", or "Cannot find the database xxxxx"
I certainly hope you can review your code again
Hope this helps :)
Mar 07, 2014 04:31 AM|PatriceSc|LINK
So it seems you try to use a connection which is not opened yet. Could it be that if the connection fails to open you ignore the exception and keep running your code and then run into this exception you didn't expected ?
Mar 07, 2014 05:29 AM|Tomiu|LINK
I use the same code for the Database thats in the same server with the Webapp and it works fine. I have this problem only if the Database is on a different server.
Mar 07, 2014 05:41 AM|PatriceSc|LINK
Still it could happen:
- on the first server the connection string is ok, open works and the the code that follow works
- on the second server the connection string is wrong, open fails but for some reason you ignore the exception and when later your code uses this connection you have an error because the connection is not opened
So having your code running fine on the first server doesn't really help. Please tell use explicitely if you catch (and possibly ignore) exceptions when the connection is opened and on which line the current exception happens.
I don't know this db but technically speaking the exception message tells that you try to use a connection for an operation that requires an opened connection and it is not. So either you never opened the connection, either you tried to opened it and fails
silently and then you have this exception which is just a consequence of an earlier problem.
When debugging it's best to never assume something but to check everything.
Mar 10, 2014 11:49 AM|Tomiu|LINK
I found the solution. I had to modify the pg_hba.conf file