Cannot to connect to SQL Server using FreeTDS and ODBC (raspberry pi raspbian)












2















Using a Raspberry Pi with Raspbian 9, I'm trying to connect to an Azure SQL database using ODBC (pip installed it from the shell) with FreeTDS (version 108)



Up until now, I have tried the following:



In /etc/odbcinst.ini:



[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so


In my /etc/odbc.ini



[name]
Driver=FreeTDS
ServerName = {MyServerString from Azure MS-SQL}
Database = {My database name from Azure MSQ-SQL}
TDS_Version = auto


In the FreeTDS.config file:



Created this block:



[name]
host = {MyServerString from Azure MSQ SQL}
port = 1433
tds version = auto


When I run the following command:



tsql -S {name} -U {my_username} -P {my_password}


I get the result



No errors ( 1> )


So I believe I am connected to the database.



However, when I run my Python code. I get an error. My database connection block is below



#Database setup
conDEBUG = "DRIVER={FreeTDS};Database={MyDGName};SERVER=tcp:{MyDB}.database.windows.net;UID={myUID};PWD={myPWD}"
conDEBUG = urllib.parse.quote_plus(conDEBUG)
conDEBUG = "mssql+pyodbc:///?odbc_connect=%s" % conDEBUG
app.config['SQLALCHEMY_DATABASE_URI'] = conDEBUG
db = SQLAlchemy(app)


I also tried adding 'TDS_Version=auto' to the conDEBUG string, this didn't work either.



The specific error I am getting:




('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')











share|improve this question

























  • Try removing tcp: from SERVER=tcp:{MyDB}.database.windows.net. protocol:servername is supported by Microsoft's ODBC driver for SQL Server, but not by FreeTDS ODBC.

    – Gord Thompson
    Nov 22 '18 at 17:02













  • Tried it. No success.. same error

    – user122661
    Nov 22 '18 at 17:50
















2















Using a Raspberry Pi with Raspbian 9, I'm trying to connect to an Azure SQL database using ODBC (pip installed it from the shell) with FreeTDS (version 108)



Up until now, I have tried the following:



In /etc/odbcinst.ini:



[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so


In my /etc/odbc.ini



[name]
Driver=FreeTDS
ServerName = {MyServerString from Azure MS-SQL}
Database = {My database name from Azure MSQ-SQL}
TDS_Version = auto


In the FreeTDS.config file:



Created this block:



[name]
host = {MyServerString from Azure MSQ SQL}
port = 1433
tds version = auto


When I run the following command:



tsql -S {name} -U {my_username} -P {my_password}


I get the result



No errors ( 1> )


So I believe I am connected to the database.



However, when I run my Python code. I get an error. My database connection block is below



#Database setup
conDEBUG = "DRIVER={FreeTDS};Database={MyDGName};SERVER=tcp:{MyDB}.database.windows.net;UID={myUID};PWD={myPWD}"
conDEBUG = urllib.parse.quote_plus(conDEBUG)
conDEBUG = "mssql+pyodbc:///?odbc_connect=%s" % conDEBUG
app.config['SQLALCHEMY_DATABASE_URI'] = conDEBUG
db = SQLAlchemy(app)


I also tried adding 'TDS_Version=auto' to the conDEBUG string, this didn't work either.



The specific error I am getting:




('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')











share|improve this question

























  • Try removing tcp: from SERVER=tcp:{MyDB}.database.windows.net. protocol:servername is supported by Microsoft's ODBC driver for SQL Server, but not by FreeTDS ODBC.

    – Gord Thompson
    Nov 22 '18 at 17:02













  • Tried it. No success.. same error

    – user122661
    Nov 22 '18 at 17:50














2












2








2


1






Using a Raspberry Pi with Raspbian 9, I'm trying to connect to an Azure SQL database using ODBC (pip installed it from the shell) with FreeTDS (version 108)



Up until now, I have tried the following:



In /etc/odbcinst.ini:



[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so


In my /etc/odbc.ini



[name]
Driver=FreeTDS
ServerName = {MyServerString from Azure MS-SQL}
Database = {My database name from Azure MSQ-SQL}
TDS_Version = auto


In the FreeTDS.config file:



Created this block:



[name]
host = {MyServerString from Azure MSQ SQL}
port = 1433
tds version = auto


When I run the following command:



tsql -S {name} -U {my_username} -P {my_password}


I get the result



No errors ( 1> )


So I believe I am connected to the database.



However, when I run my Python code. I get an error. My database connection block is below



#Database setup
conDEBUG = "DRIVER={FreeTDS};Database={MyDGName};SERVER=tcp:{MyDB}.database.windows.net;UID={myUID};PWD={myPWD}"
conDEBUG = urllib.parse.quote_plus(conDEBUG)
conDEBUG = "mssql+pyodbc:///?odbc_connect=%s" % conDEBUG
app.config['SQLALCHEMY_DATABASE_URI'] = conDEBUG
db = SQLAlchemy(app)


I also tried adding 'TDS_Version=auto' to the conDEBUG string, this didn't work either.



The specific error I am getting:




('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')











share|improve this question
















Using a Raspberry Pi with Raspbian 9, I'm trying to connect to an Azure SQL database using ODBC (pip installed it from the shell) with FreeTDS (version 108)



Up until now, I have tried the following:



In /etc/odbcinst.ini:



[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/odbc/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so


In my /etc/odbc.ini



[name]
Driver=FreeTDS
ServerName = {MyServerString from Azure MS-SQL}
Database = {My database name from Azure MSQ-SQL}
TDS_Version = auto


In the FreeTDS.config file:



Created this block:



[name]
host = {MyServerString from Azure MSQ SQL}
port = 1433
tds version = auto


When I run the following command:



tsql -S {name} -U {my_username} -P {my_password}


I get the result



No errors ( 1> )


So I believe I am connected to the database.



However, when I run my Python code. I get an error. My database connection block is below



#Database setup
conDEBUG = "DRIVER={FreeTDS};Database={MyDGName};SERVER=tcp:{MyDB}.database.windows.net;UID={myUID};PWD={myPWD}"
conDEBUG = urllib.parse.quote_plus(conDEBUG)
conDEBUG = "mssql+pyodbc:///?odbc_connect=%s" % conDEBUG
app.config['SQLALCHEMY_DATABASE_URI'] = conDEBUG
db = SQLAlchemy(app)


I also tried adding 'TDS_Version=auto' to the conDEBUG string, this didn't work either.



The specific error I am getting:




('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')








sql-server tsql raspbian pyodbc freetds






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 5:10









marc_s

572k12811061253




572k12811061253










asked Nov 22 '18 at 2:27









user122661user122661

1112




1112













  • Try removing tcp: from SERVER=tcp:{MyDB}.database.windows.net. protocol:servername is supported by Microsoft's ODBC driver for SQL Server, but not by FreeTDS ODBC.

    – Gord Thompson
    Nov 22 '18 at 17:02













  • Tried it. No success.. same error

    – user122661
    Nov 22 '18 at 17:50



















  • Try removing tcp: from SERVER=tcp:{MyDB}.database.windows.net. protocol:servername is supported by Microsoft's ODBC driver for SQL Server, but not by FreeTDS ODBC.

    – Gord Thompson
    Nov 22 '18 at 17:02













  • Tried it. No success.. same error

    – user122661
    Nov 22 '18 at 17:50

















Try removing tcp: from SERVER=tcp:{MyDB}.database.windows.net. protocol:servername is supported by Microsoft's ODBC driver for SQL Server, but not by FreeTDS ODBC.

– Gord Thompson
Nov 22 '18 at 17:02







Try removing tcp: from SERVER=tcp:{MyDB}.database.windows.net. protocol:servername is supported by Microsoft's ODBC driver for SQL Server, but not by FreeTDS ODBC.

– Gord Thompson
Nov 22 '18 at 17:02















Tried it. No success.. same error

– user122661
Nov 22 '18 at 17:50





Tried it. No success.. same error

– user122661
Nov 22 '18 at 17:50












1 Answer
1






active

oldest

votes


















0














Here's the function I use for connecting via SQLAlchemy to SQL Server over pyodbc:



def mssql_connect(con_string): 
""" Connects to the specified db via ODBC. """
def connect():
return pyodbc.connect(con_string, autocommit=True)

db = create_engine('mssql://', creator=connect, encoding='cp1252')
db.echo = False

return db

mssql_connect("DRIVER={FreeTDS};SERVER={MyDB}.database.windows.net;PORT=1433;DATABASE={dbname};UID={myUID};PWD={myPWD};TDS_Version=7.3;")


Depending on your version of FreeTDS, you may have to replace TDS_Version=7.3 with TDS_Version=7.2 or TDS_Version=7.1. Good luck!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423067%2fcannot-to-connect-to-sql-server-using-freetds-and-odbc-raspberry-pi-raspbian%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Here's the function I use for connecting via SQLAlchemy to SQL Server over pyodbc:



    def mssql_connect(con_string): 
    """ Connects to the specified db via ODBC. """
    def connect():
    return pyodbc.connect(con_string, autocommit=True)

    db = create_engine('mssql://', creator=connect, encoding='cp1252')
    db.echo = False

    return db

    mssql_connect("DRIVER={FreeTDS};SERVER={MyDB}.database.windows.net;PORT=1433;DATABASE={dbname};UID={myUID};PWD={myPWD};TDS_Version=7.3;")


    Depending on your version of FreeTDS, you may have to replace TDS_Version=7.3 with TDS_Version=7.2 or TDS_Version=7.1. Good luck!






    share|improve this answer




























      0














      Here's the function I use for connecting via SQLAlchemy to SQL Server over pyodbc:



      def mssql_connect(con_string): 
      """ Connects to the specified db via ODBC. """
      def connect():
      return pyodbc.connect(con_string, autocommit=True)

      db = create_engine('mssql://', creator=connect, encoding='cp1252')
      db.echo = False

      return db

      mssql_connect("DRIVER={FreeTDS};SERVER={MyDB}.database.windows.net;PORT=1433;DATABASE={dbname};UID={myUID};PWD={myPWD};TDS_Version=7.3;")


      Depending on your version of FreeTDS, you may have to replace TDS_Version=7.3 with TDS_Version=7.2 or TDS_Version=7.1. Good luck!






      share|improve this answer


























        0












        0








        0







        Here's the function I use for connecting via SQLAlchemy to SQL Server over pyodbc:



        def mssql_connect(con_string): 
        """ Connects to the specified db via ODBC. """
        def connect():
        return pyodbc.connect(con_string, autocommit=True)

        db = create_engine('mssql://', creator=connect, encoding='cp1252')
        db.echo = False

        return db

        mssql_connect("DRIVER={FreeTDS};SERVER={MyDB}.database.windows.net;PORT=1433;DATABASE={dbname};UID={myUID};PWD={myPWD};TDS_Version=7.3;")


        Depending on your version of FreeTDS, you may have to replace TDS_Version=7.3 with TDS_Version=7.2 or TDS_Version=7.1. Good luck!






        share|improve this answer













        Here's the function I use for connecting via SQLAlchemy to SQL Server over pyodbc:



        def mssql_connect(con_string): 
        """ Connects to the specified db via ODBC. """
        def connect():
        return pyodbc.connect(con_string, autocommit=True)

        db = create_engine('mssql://', creator=connect, encoding='cp1252')
        db.echo = False

        return db

        mssql_connect("DRIVER={FreeTDS};SERVER={MyDB}.database.windows.net;PORT=1433;DATABASE={dbname};UID={myUID};PWD={myPWD};TDS_Version=7.3;")


        Depending on your version of FreeTDS, you may have to replace TDS_Version=7.3 with TDS_Version=7.2 or TDS_Version=7.1. Good luck!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 18:36









        FlipperPAFlipperPA

        6,95322043




        6,95322043






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53423067%2fcannot-to-connect-to-sql-server-using-freetds-and-odbc-raspberry-pi-raspbian%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python