0

I have a code running on server named 'MGSF.xabis.com'. the main function of the code is to insert data to db table. when i give SQL db table of same server it works fine, but when i want to insert data to SQL DB Table of another server with name "poeh.xabis.com", it is throwing me below error:

pypyodbc.DatabaseError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.')

So i don know whether it is possible we can insert data into another server while placing the flask app to insert in another server.

from flask import Flask
from flask import jsonify
import mysql.connector
import pypyodbc as pyodbc

app = Flask(__name__)

@app.route('/')
def hello():
    print("Just go inside ")
    return 'Atlast got inside Page'

@app.route('/WritetoFile/<filename>')
def WritetoaFile(filename):
    f = open(filename+".txt", "a")
    f.write("Now the file has more content!")
    f.close()

    # open and read the file after the appending:
    f = open(filename+".txt", "r")

    return  f.read()

@app.route('/insertdataToDBFile/<dbname>')
def writetodbfile(dbname):
    conn = pyodbc.connect('Driver={SQL Server};'
                          'Server=poeh.xabis.com;'
                          'Database=SelfHeal;'
                          'Trusted_Connection=yes;'
                          'PORT=1433;')
     
    cursor = conn.cursor()
    cursor.execute('''
                INSERT INTO Issue VALUES('Hi;llos','20120618 10:34:09 AM','kl','prod','20120618 10:34:09 AM','yes','yes','20120618 10:34:09 AM','yes','123','poem')
                ''')
    conn.commit()
    cursor.execute('SELECT * FROM SelfHeal.dbo.Issue')
     
    for row in cursor:
        print(row)
    return (str(cursor.rowcount) + " record inserted.")

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8015, debug=True)

the above code is located on 'MGSF.xabis.com' and this data should be inserted to the MSSQL DB Table present **"poeh.xabis.com" **

MGSF.xabis.com and poeh.xabis.com are two remote windows servers

James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0