Jump to content

MS Azure MYSQL Program Connection?

Go to solution Solved by LightCode Gaming,

Found out what was closing it. Azure has a whitelist enabled for trial users. 

So I'm currently writing up a web server that will take requests of data from a My SQL DB that is hosted on Azure. I've been writing it using Python, but I keep getting silent crashes that don't trigger try/catch blocks.

 

Here's a snippet from the _mysql attempt; this "succeeds" without submitting - no errors are thrown to break the attempt. 

def view_profile(args):
    try:
        db=_mysql.connect(host=server,port=3306,user=username,
                  passwd=password,db=database)
        db.query("SELECT * FROM accounts")
        rows=db.store_result()
        print(str(rows[1]))
        
        return 1
    except:
        return 0

I had print statements between each line to make sure it was doing something, but it never completed the connection phase. (Note: The above code is using the _mysql library; ODBC attempt is below)

 

 

Here's an example of what I have for the ODBC version. 

connectString = 'Database=<DB HERE>;Data Source=<Server here>;User Id=<login cred>;Password=<PW cred>'

def register(args):   
    try:        
        cnxn = pyodbc.connect(connectString)
        cursor = cnxn.cursor()
        cursor.execute("INSERT INTO accounts (Email, Password, FName, LName, DoB, Phone, LastLongitute, LastLatitude) values ('"
                        + args[0] + "', '" + args[1] + "', '" + args[2] + "', '"
                        + args[3] + "', '" + args[4] + "', '" + args[5] + "', "
                        + args[6] + ", " +args[7] + ")")
        cnxn.commit()
        cnxn.close()
        return 1
    except:
        return 0

 

 

 

 

Both of the above codes "succeeds" without submitting data, but fail to even connect to the server. Any idea what I'm doing wrong here?

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to comment
Share on other sites

Link to post
Share on other sites

UPDATE: Now using a different library and getting better results.

 

import psycopg2

conn = psycopg2.connect(connstring)
print("connected.")
cursor = conn.cursor()
print("cursor made.")
cursor.execute("INSERT INTO accounts values ('"
     + args[0] + "', '" + args[1] + "', '" + args[2] + "', '"
     + args[3] + "', '" + args[4] + "', '" + args[5] + "', "
     + args[6] + ", " +args[7] + ")")
print("executing...")
conn.commit()
print("committing...")
conn.close()

I'm now getting this error: 

psycopg2.OperationalError: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.

 

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to comment
Share on other sites

Link to post
Share on other sites

Found out what was closing it. Azure has a whitelist enabled for trial users. 

GIGABYTE Z97MX-G516GB DDR3 | I5 4690k @ 4.4ghz | 1TB SSHD, 500GB HDD, 128GB SSD | GTX 1070 8GB | Corsair Graphite 230 | EVGA 650W | Hyper 212 EVO

 

Cinebench R15: 636(all cores), 127FPS

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×