MS SQL Database connection

H

Hitesh

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
 
D

Dennis Lee Bieber

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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
T

Tim Golden

Hitesh said:
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>
 
H

Hitesh

Hitesh said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top