WebFaction
Community site: login faq

In my app i am trying to save the database element into an json file.Please see my views.py for doing:

connstr = 'DRIVER={SQL Server};SERVER=dev_appserver;DATABASE=DemoApp;'
conn = pyodbc.connect(connstr)
cursor = conn.cursor()

cursor.execute("""
            SELECT book_id, book_name, author_name, publisher_name, email, bookref
            FROM Book
            """)

rows = cursor.fetchall()

rowarray_list = []
for row in rows:
    t = (row.book_id, row.book_name, row.author_name, row.publisher_name, 
         row.email, row.bookref)
    rowarray_list.append(t)

j = json.dumps(rowarray_list)
rowarrays_file = 'student_rowarrays.json'
f = open(rowarrays_file,'w')
print >> f, j

objects_list = []
for row in rows:
    d = collections.OrderedDict()
    d['book_id'] = row.book_id
    d['book_name'] = row.book_name
    d['author_name'] = row.author_name
    d['publisher_name'] = row.publisher_name
    d['email'] = row.email
    d['bookref'] = row.bookref
    objects_list.append(d)

j = json.dumps(objects_list)
objects_file = 'student_objects.json'
f = open(objects_file,'w')
print >> f, j

conn.close()

my models.py

class Book(models.Model):

    book_id=models.AutoField(primary_key=True,unique=True)
    book_name=models.CharField(max_length=30)
    author_name=models.CharField(max_length=30)
    publisher_name=models.CharField(max_length=40)
    email = models.EmailField()
    bookref = models.CharField(max_length=10)
    class Meta:
        db_table = u'Book'

    def __unicode__(self):
        return "%d %s %s %s %s" % (self.book_id,self.book_name, self.author_name,self.publisher_name,self.email,self.bookref)

while running the app,i am getting this error:

('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')

In my system i installed pyodbc and unixODBC, i am using mysql database and running the app in django development server. Please help me in doing the same.

Thanks

asked 03 Apr '13, 23:28

pychu
3148
accept rate: 0%

edited 03 Apr '13, 23:59

ryans ♦♦
5.0k93360

Are you getting this in pyodbc.connect()? Or maybe cursor.execute()?

Also, can you explain how exactly you installed pyodbc and unixODBC under your WebFaction account?

(04 Apr '13, 00:04) ryans ♦♦

yes sir,i installed both using easy_install pyodbc and easy_install unixODBC comments

(04 Apr '13, 00:07) pychu

If this is happening in pyodbc.connect(), then the rest of the view is inconsequential and suggests that the issue is with your connection string. Are you able to connect to this database exactly as your connstr specifies, but manually via mysql?

(04 Apr '13, 00:14) ryans ♦♦

I already created models in database,i am using the same in my app uisng the following in settings host:localhots,username:root,password:sa,port:3306

(04 Apr '13, 00:23) pychu

Is this Linux? Then:

You need to configure the files: /etc/odbc.ini /etc/odbcinst.ini

You need to have an entry for your driver in your connection string: DRIVER={SQL Server};

For example

[SQL Server] Description=Microsoft ODBC Driver 11 for SQL Server Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2260.0 Threading=1 UsageCount=1 Trace=1 TraceFile=/home/super/SuperFROG/daimler/log/odbc.mssql.trace

permanent link

answered 11 Aug '14, 14:53

isgoed
111
accept rate: 0%

WebFaction is a managed, shared hosting provider. Customers don't have access to modify config in /etc.

(11 Aug '14, 15:02) seanf

Then you must hope that it is already properly configured and supply the proper driver in "DRIVER={SQL Server};"

(11 Aug '14, 15:12) isgoed
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×337
×30
×3

question asked: 03 Apr '13, 23:28

question was seen: 18,473 times

last updated: 11 Aug '14, 15:12

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM