0

I have a problem: I connected to DB on one server (the one thats app is running) and it works fine. But if I want to connect to other DB on other server, it doesn't work - 500 error pops up. It seems like there's a problem even with connecting to DB (have done some tests). I am using SQL Server 2012 and have no idea what to do next.

Some infos:

  • servers can't connect to internet so every installation is a painfull process

  • on the first one my web app is running

  • on the second server I have nothing - no python, no flask, no anaconda. There's only my wanted DB and SQL Server 2012.

  • already enabled Windows Authenticaton on second server

  • on usual computer as a running program everything works pretty well

Is it even possible to use two connection to two different servers? Do I have to install python and pyodbc on second server to make it work?

Below I show snippet of code:

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0};' 
                  'Server=whatever1;'
                  'Database=whatever2;'
                  'Trusted_Connection=yes;')

cursor = conn.cursor()
cursor.execute("SELECT column1, column2 FROM dbo.database1")
kursor = cursor.fetchall()

for row1 in kursor:
    ...

cursor.close()
conn2 = pyodbc.connect('Driver={SQL Server Native Client 11.0};' 
                  'Server=whatever3;'
                  'Database=whatever4;'
                  'Trusted_Connection=yes;')


cursor = conn2.cursor()
cursor.execute("SELECT column1 FROM dbo.database2")
"""
sth = cursor.fetchone()
... 
cursor.close()
conn.close()
conn2.close()

Tried a lot, nothing helped. Thanks from the bottom of my heart for very tip!

EDIT

I think I have tried everything that came to my mind and visited every possible website taht I have thought it had solution somewhere. Since I wrote this post, I discovered things:

  • the problem is surely with connection with server no 2, because I discovered possibility of getting error logs and error has a 'Login failed for user 'Domain\Server$' ' so that's for sure

  • the login thats in logs doesn't exist in tab Security in Logins, and I don't know to which it belongs so that I don't know who should get appropriate permissions and how to do that

  • in logs in ms sql server on the 2nd server I found the reason: Could not find a login matching the name provided.

  • Windows Authentication enabled on both, and also - when I run a program which connects to the SQL Server (the second one) and it is run on the first server (where the app runs) it works pretty well and no error, using trusted_connection = yes

Any ideas what can be the cause? I am struggling with this for so long that I have already started to visit same places and asking same questins on and on, and still no answer on the horizon.

Thanks buds for every tip!

  • Check your db service – Johnny Mar 24 '20 at 09:33
  • What exactly do you mean? :| – sianeczniak Mar 24 '20 at 09:35
  • Can you connect to your database remotely correctly? – Johnny Mar 24 '20 at 09:40
  • Yes, everything seems to work fine and without any problems. – sianeczniak Mar 24 '20 at 09:52
  • Are you stuck at 500 error? – Johnny Mar 24 '20 at 10:00
  • Yes, didn't I say that? Databases work fine. I think that if one of them didn't, the simple function wouldn't work. – sianeczniak Mar 24 '20 at 10:05
  • can you show the error messags? – Johnny Mar 24 '20 at 10:14
  • Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application. – sianeczniak Mar 24 '20 at 10:21
  • Of course you can connect to as many different DBs / external services / etc as you want (except o course for OS-level limits on open sockets etc). And you don't need to install Python nor anything special on the servers where those DBs or whatever are running. It's only a server / client connection setup issue, nothing to do with Python itself. – bruno desthuilliers Mar 24 '20 at 10:35
  • Also you should have much more details about the error in your application's logs or stderr (depending on how you run it and how it's configured). – bruno desthuilliers Mar 24 '20 at 10:36
  • Hint: run your code from a Python shell, you'll quickly find out what goes wrong (at the Python client level at least - but this should give you hints about your configuration issues). – bruno desthuilliers Mar 24 '20 at 10:38
  • I am using VS Code and there is no output connected to error :/ The thing is as a program it runs OK, if I run it through Python shell or VS Code and click 'Execute', but if I go on IP where's my app running, and try to search sth (my app is a searcher using databases), it doesn't work then. So the main case is my app is whether sooo sensitive for potential errors taht don't show while simple running by hand or there's a problem with connection and I am wondering what I have to do to make the connection withsecond server work – sianeczniak Mar 24 '20 at 10:48
  • under which identity pool your application is running? try to enable debug mode so Flask will actually tell you what the error is. `if __name__ == '__main__': app.debug = True app.run()` – Jalpa Panchal Mar 25 '20 at 08:30
  • Under LocalSystem. I discovered that first server has no access to second server and the error is logged: (18456) (SQLDriverConnect); [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user . Should I have trusted_connection=yes or no and then use login and password for my server, where the app is running? – sianeczniak Mar 25 '20 at 11:00

0 Answers0