Welcome, Guest
Python Scripts for ComicRack

TOPIC: Request for assistance

Request for assistance 8 years 7 months ago #3105

Hi all

I'm trying to get pymssql (pymssql.sourceforge.net/) to work from within CR. I think the installer is registering itself and building the _mssql module within my local python instance, but not within CR. Can anyone verify this? Is there a way to build this "on the fly" within CR?

If anyone can get this working or can specify an alternate method to connect a python script to SQL Server, I would be much obliged!

Thanks
The administrator has disabled public write access.

Re:Request for assistance 8 years 7 months ago #3113

  • wadegiles
  • wadegiles's Avatar
  • Offline
  • Gold Boarder
  • Posts: 248
  • Thank you received: 3
  • Karma: 20
How about using ODBC instead? I don't know for sure but the modules you need for that might already be available in IronPython scripting.

This page is good: http://www.time-travellers.org/shane/howtos/MS-SQL-Express-Python-HOWTO.html

This might be helpful but it might also be overkill for your needs: http://www.petersblog.org/node/847

You are probably trying to use a module not included with the scripting environment. I have not been able to accomplish in the past so if you or anyone can make 3rd party modules visible from withing ComicRack PLEASE share that information.
The administrator has disabled public write access.

Re:Request for assistance 8 years 7 months ago #3126

No good. Looks like ODBC is also a third-party module, or at least it's not included in IronPython.
The administrator has disabled public write access.

Re:Request for assistance 8 years 7 months ago #3127

  • wadegiles
  • wadegiles's Avatar
  • Offline
  • Gold Boarder
  • Posts: 248
  • Thank you received: 3
  • Karma: 20
I don't know why I didn't think of this at first, but you should try using the .NET Framework classes. Import the namespaces you need and set up a reference.

SqlConnection class documentation is here:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(VS.80).aspx
Last Edit: 8 years 7 months ago by wadegiles.
The administrator has disabled public write access.

Re:Request for assistance 8 years 7 months ago #3129

Can you give an example of how to use that in Python? I'm not sure the syntax (would it be the same)?
The administrator has disabled public write access.

Re:Request for assistance 8 years 7 months ago #3130

  • wadegiles
  • wadegiles's Avatar
  • Offline
  • Gold Boarder
  • Posts: 248
  • Thank you received: 3
  • Karma: 20
Assuming your connection string is set for the variable connectionString

Your import statements should be:

clr.AddReferenceByName( "System.Data.SqlClient" )
from System.Data.SqlClient import *


In the code, to set up an opened connection object:

sqlDb = SqlConnection(connectionString)
sqlDb.Open()


The syntax difference when using .NET classes in IronPython is that variables are not strongly declared with their types and there is no new operator for instantiation. In C#, the connection object could be instantiated using this line of code: SqlConnection sqlDb = new SqlConnection(connectionString);
Last Edit: 8 years 7 months ago by wadegiles.
The administrator has disabled public write access.
Time to create page: 0.174 seconds

Who's Online

We have 199 guests and 5 members online