MS SQL Database connection

Discussion in 'Python' started by Hitesh, Mar 4, 2007.

  1. Hitesh

    Hitesh Guest

    Hi currently I am using DNS and ODBC to connect to MS SQL database.
    Is there any other non-dns way to connect? If I want to run my script
    from different server I first have to create the DNS in win2k3.

    Thank you,
    hj
     
    Hitesh, Mar 4, 2007
    #1
    1. Advertising

  2. On 4 Mar 2007 14:33:59 -0800, "Hitesh" <> declaimed
    the following in comp.lang.python:

    >
    > Hi currently I am using DNS and ODBC to connect to MS SQL database.
    > Is there any other non-dns way to connect? If I want to run my script
    > from different server I first have to create the DNS in win2k3.
    >

    I suspect you mean DSN (Data Source Name), not DNS (Domain Name
    System)...

    Study the options for M$ SQL Server -- it may be possible to specify
    everything as a connection string to the ODBC connection module...
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Mar 5, 2007
    #2
    1. Advertising

  3. Hitesh

    Tim Golden Guest

    Hitesh wrote:
    > Hi currently I am using DNS and ODBC to connect to MS SQL database.
    > Is there any other non-dns way to connect? If I want to run my script
    > from different server I first have to create the DNS in win2k3.


    Here are several ways to connect to an MSSQL database w/o
    having to create "DNS" or anything else in win2k3 ;)

    There are other ways (the slightly stale MSSQL module
    from Object Craft, for example, which still works fine
    for Python <= 2.3).

    TJG

    <code>
    def adodbapi_connection (server, database, username, password):
    #
    # http://adodbapi.sf.net
    #
    import adodbapi
    connectors = ["Provider=SQLOLEDB"]
    connectors.append ("Data Source=%s" % server)
    connectors.append ("Initial Catalog=%s" % database)
    if username:
    connectors.append ("User Id=%s" % username)
    connectors.append ("Password=%s" % password)
    else:
    connectors.append("Integrated Security=SSPI")
    return adodbapi.connect (";".join (connectors))

    def pymssql_connection (server, database, username, password):
    #
    # http://pymssql.sf.net
    #
    import pymssql
    if not username:
    raise RuntimeError, "Unable to use NT authentication for pymssql"
    return pymssql.connect (user=username, password=password,
    host=server, database=database)

    def pyodbc_connection (server, database, username, password):
    #
    # http://pyodbc.sf.net
    #
    import pyodbc
    connectors = ["Driver={SQL Server}"]
    connectors.append ("Server=%s" % server)
    connectors.append ("Database=%s" % database)
    if username:
    connectors.append ("UID=%s" % username)
    connectors.append ("PWD=%s" % password)
    else:
    connectors.append ("TrustedConnection=Yes")
    return pyodbc.connect (";".join (connectors))

    </code>
     
    Tim Golden, Mar 5, 2007
    #3
  4. Hitesh

    Hitesh Guest

    On Mar 5, 4:44 am, Tim Golden <> wrote:
    > Hitesh wrote:
    > > Hi currently I am using DNS and ODBC to connect to MS SQL database.
    > > Is there any other non-dns way to connect? If I want to run my script
    > > from different server I first have to create the DNS in win2k3.

    >
    > Here are several ways to connect to an MSSQL database w/o
    > having to create "DNS" or anything else in win2k3 ;)
    >
    > There are other ways (the slightly stale MSSQL module
    > from Object Craft, for example, which still works fine
    > for Python <= 2.3).
    >
    > TJG
    >
    > <code>
    > def adodbapi_connection (server, database, username, password):
    > #
    > #http://adodbapi.sf.net
    > #
    > import adodbapi
    > connectors = ["Provider=SQLOLEDB"]
    > connectors.append ("Data Source=%s" % server)
    > connectors.append ("Initial Catalog=%s" % database)
    > if username:
    > connectors.append ("User Id=%s" % username)
    > connectors.append ("Password=%s" % password)
    > else:
    > connectors.append("Integrated Security=SSPI")
    > return adodbapi.connect (";".join (connectors))
    >
    > def pymssql_connection (server, database, username, password):
    > #
    > #http://pymssql.sf.net
    > #
    > import pymssql
    > if not username:
    > raise RuntimeError, "Unable to use NT authentication for pymssql"
    > return pymssql.connect (user=username, password=password,
    > host=server, database=database)
    >
    > def pyodbc_connection (server, database, username, password):
    > #
    > #http://pyodbc.sf.net
    > #
    > import pyodbc
    > connectors = ["Driver={SQL Server}"]
    > connectors.append ("Server=%s" % server)
    > connectors.append ("Database=%s" % database)
    > if username:
    > connectors.append ("UID=%s" % username)
    > connectors.append ("PWD=%s" % password)
    > else:
    > connectors.append ("TrustedConnection=Yes")
    > return pyodbc.connect (";".join (connectors))
    >
    > </code>



    Thank you.
    And I yes I meant DSN not DNS (my mistake, thank you for catching
    it ;)

    hj
     
    Hitesh, Mar 5, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. IntraRELY

    sql database connection string storage

    IntraRELY, Nov 16, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    438
    Steven Cheng[MSFT]
    Nov 17, 2004
  2. Mythran
    Replies:
    5
    Views:
    5,001
    Mythran
    Oct 5, 2005
  3. Jon Delano
    Replies:
    18
    Views:
    2,473
    Jon Delano
    Nov 29, 2005
  4. _XaToA_
    Replies:
    0
    Views:
    2,248
    _XaToA_
    Oct 30, 2003
  5. Replies:
    0
    Views:
    405
Loading...

Share This Page