slow sql server DB reads

B

bart

I run a python website on a IIS server. I replaced my flat file DB
with SQL server, but the reads are very slow. 7 seconds for 3 querrys
like these

conn= adodbapi.connect( "Provider=SQLOLEDB.1;Persist Security
Info=False;User ID=sa;Password=xxx;Initial Catalog=dlpl;Data
Source=(local)" )
crsr = conn.cursor()
sql = "select SessionKey, SessionValue from ASPSessionState
where GUID='%s'" % self.id
crsr.execute(sql)
while 1:
info = crsr.fetchone()
if not info:
break
strKey = str(info[0])

Opening the database is already good for 2 seconds.
Anyone know how to speed it up?
 
D

Dennis Lee Bieber

sql = "select SessionKey, SessionValue from ASPSessionState
where GUID='%s'" % self.id
crsr.execute(sql)

Recommendation is to use something of the nature

sql = "select .... where GUID=%s"
crsr.execute(sql, self.id)

.execute() should properly quote the argument.
while 1:
info = crsr.fetchone()

Probably not a speed improvement but...

for info in crsr.fetchall(): #or something like that, check the
# api spec
strKey = str(info[0])

I presume you make use of SessionValue somewhere in the program
<G>

--
 
L

Larry Bates

If GUID is not a key in the database make it one. That
way you won't have to do serial reads through the entire
table to locate matching entries.

It is hard to be more specific because we don't know how
many records are in ASPSessionState table. If there are
only a few, the problem is probably elsewhere. If there
are many, indexing on GUID would provide speed improvement.

Larry Bates
 

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

Forum statistics

Threads
474,240
Messages
2,571,205
Members
47,844
Latest member
ChanceGris

Latest Threads

Top