Janos, I tried the ODBC way and it worked! I was about to give up and do it in C#<br>or some other language but I love Python so much I wanted it to work. <br><br>Thank you SO MUCH!<br><br>And thanks to all of you who helped as well!
<br>You folks are the best. <br><br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><br>Message: 6<br>Date: Wed, 23 May 2007 08:07:35 +0200
<br>From: J?nos Juh?sz <<a href="mailto:janos.juhasz@VELUX.com">janos.juhasz@VELUX.com</a>><br>Subject: Re: [Tutor] MSSQL Connection<br>To: <a href="mailto:tutor@python.org">tutor@python.org</a><br>Message-ID:<br> <
<a href="mailto:OFD30D5C16.F0DCE181-ONC12572E4.001F1BB3-C12572E4.0021A6AC@velux.com">OFD30D5C16.F0DCE181-ONC12572E4.001F1BB3-C12572E4.0021A6AC@velux.com</a>><br>Content-Type: text/plain; charset="US-ASCII"<br>
<br>Hi Leon,<br><br><br>> > Hi John,<br>> ><br>> > Here's the code (I do have permissions to truncate, works manually<br>under<br>> > the same user.<br>> ><br>> ><br>> > import pymssql
<br>> ><br>> > con = pymssql.connect<br>> > (host='server',user='user',password='pwd',database='DB_QA')<br>> > cur = con.cursor()<br>> ><br>> ><br>> > query="truncate TABLE bbConsolidatedMessageAcks"
<br>> > cur.execute(query)<br>> > print "Deleted Records: %d" % cur.rowcount<br>> ><br><br>I use two alternatives to connect to mssql server.<br><br>ADODB connection via win32com.client<br>------------------
<br>import win32com.client<br><br>cn =win32com.client.Dispatch('ADODB.connection')<br>cn.Provider='sqloledb'<br>cn.Open('Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security<br>Info=False;Initial Catalog=production;Data Source=036fefersqls001')
<br># The argument of cn.Open(), the connection string can be created very<br>easy on windows.<br># Create a conn.udl on your desktop<br># Open it with double click, and build a new connection string, test it,<br>save it
<br># Copy and paste from your .udl<br><br>stockcode = '100701-06'<br>sql = "select * from stocks where stock = '%s'" % stockcode<br><br>print sql<br>rs = win32com.client.Dispatch('ADODB.recordset
')<br>rs.Open(sql, cn)<br>print rs.Fields[0].Value<br>rs.Close()<br><br>cn.Close()<br>-----------------<br><br>But I usually use ODBC with this kind of class.<br><br>import dbi, odbc<br><br>class myDB:<br> def __init__(self):
<br> """Open a new connection."""<br> <a href="http://self.cn">self.cn</a> =<br>odbc.odbc('DSN=myDB;UID=query;PWD=query;DATABASE=myDB')<br><br> def closeDB(self):
<br> """Close the connection."""<br> self.cn.close()<br><br> def Execute(self, sql):<br> cr = self.cn.cursor()<br> cr.execute
(sql)<br> cr.close()<br><br> def Query(self, sql):<br> try:<br> cr = self.cn.cursor()<br> cr.execute(sql)<br> self.colnames
= [field_prop[0] for field_prop in<br>cr.description]<br> self.result = cr.fetchall()<br> self.rownum = len(self.result)<br> return self.result<br> except:
<br> self.colnames = [None]<br> self.result = [[None]]<br> self.rownum = 0<br> return [[None]]<br><br>test = myDB()<br>print(test.Query
('Select * from testtable') )<br><br><br>Best regards,<br>Janos<br><br><br><br>------------------------------<br><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">
Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br>End of Tutor Digest, Vol 39, Issue 60<br>*************************************<br>
</blockquote></div><br>