Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > MS SQL Database connection

Reply
Thread Tools

MS SQL Database connection

 
 
Hitesh
Guest
Posts: n/a
 
      03-04-2007

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

 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      03-05-2007
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: web-)
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      03-05-2007
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>
 
Reply With Quote
 
Hitesh
Guest
Posts: n/a
 
      03-05-2007

On Mar 5, 4:44 am, Tim Golden <m...@timgolden.me.uk> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Add new SQL Database to App_Data need SQL Server Express installed? Michael ASP .Net 2 07-19-2009 03:09 PM
How to reference a membership database that is not in App_Data SQL Server Express database? Keith ASP .Net 1 07-03-2006 07:42 AM
SQL database table ot SQL schema Paul M ASP .Net 2 12-08-2003 04:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57