Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8555773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:12:03+00:00 2026-06-11T15:12:03+00:00

I am trying to call a SQL Server stored procedure from my Python code,

  • 0

I am trying to call a SQL Server stored procedure from my Python code, using sqlalchemy. What I’m finding is that no error is raised by the python code and the stored procedure is not executing.

Sample code:

def SaveData(self, aScrapeResult):
    sql = "EXECUTE mc.SaveFundamentalDataCSV @pSource='%s',@pCountry='%s',@pOperator='%s',@pFromCountry='%s',@pFromOperator='%s',@pToCountry='%s',@pToOperator='%s',@pSiteName='%s',@pFactor='%s',@pGranularity='%s',@pDescription='%s',@pDataType='%s',@pTechnology = '%s',@pcsvData='%s'"

    #   Need to convert the data into CSV
    util = ListToCsvUtil()
    csvValues = util.ListToCsv(aScrapeResult.DataPoints)

    formattedSQL = sql % (aScrapeResult.Source ,aScrapeResult.Country,aScrapeResult.Operator ,aScrapeResult.FromCountry ,aScrapeResult.FromOperator ,aScrapeResult.ToCountry ,aScrapeResult.ToOperator ,aScrapeResult.SiteName ,aScrapeResult.Factor ,aScrapeResult.Granularity ,aScrapeResult.Description ,aScrapeResult.DataType ,aScrapeResult.Technology ,csvValues)

    DB = create_engine(self.ConnectionString)
    DB.connect()

    result_proxy = DB.execute(formattedSQL)

    results = result_proxy.fetchall()

Examination of formatted SQL yields the following command

EXECUTE mc.SaveFundamentalDataCSV @pSource='PythonTest', @pCountry='UK',
  @pOperator='Operator', @pFromCountry='None', @pFromOperator='None', 
  @pToCountry='None', @pToOperator='None', @pSiteName='None', @pFactor='Factor', 
  @pGranularity='Hourly', @pDescription='Testing from python', 
  @pDataType='Forecast',@pTechnology = 'Electricity',
  @pcsvData='01-Jan-2012 00:00:00,01-Feb-2012 00:15:00,1,01-Jan-2012 00:00:00,01-Feb-2012 00:30:00,2';

The various versions and software in use is as follows:
SQL Server 2008 R2
Python 2.6.6
SQLAlchemy 0.6.7

I have tested my stored procedure by calling it directly in SQL Server Management Studio with the same parameters with no problem.

It’s worth stating that this point that the Python version and the SQL server version are non-changeable. I have no strong allegiance to sqlalchemy and am open to other suggestions.

Any advice would be greatly appreciated, more information can be provided if needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:12:04+00:00Added an answer on June 11, 2026 at 3:12 pm

    Fixed now but open to opinion if I’m using best practice here. I’ve used the ‘text’ object exposed by sqlalchemy, working code below:

    def SaveData(self, aScrapeResult):
        sql = "EXECUTE mc.SaveFundamentalDataCSV @pSource='%s',@pCountry='%s',@pOperator='%s',@pFromCountry='%s',@pFromOperator='%s',@pToCountry='%s',@pToOperator='%s',@pSiteName='%s',@pFactor='%s',@pGranularity='%s',@pDescription='%s',@pDataType='%s',@pTechnology = '%s',@pcsvData='%s'"
    
        #   Need to convert the data into CSV
        util = ListToCsvUtil()
        csvValues = util.ListToCsv(aScrapeResult.DataPoints)
    
        formattedSQL = sql % (aScrapeResult.Source ,aScrapeResult.Country,aScrapeResult.Operator ,aScrapeResult.FromCountry ,aScrapeResult.FromOperator ,aScrapeResult.ToCountry ,aScrapeResult.ToOperator ,aScrapeResult.SiteName ,aScrapeResult.Factor ,aScrapeResult.Granularity ,aScrapeResult.Description ,aScrapeResult.DataType ,aScrapeResult.Technology ,csvValues)
    
        DB = create_engine(self.ConnectionString)
        conn = DB.connect()
    
        t = text(formattedSQL).execution_options(autocommit=True)
    
        DB.execute(t)
    
        conn.close()
    

    Hope this proves helpful to someone else!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call a parameterized stored procedure from SQL Server 2005 in my
I'm trying to call a stored procedure (on a SQL 2005 server) from C#,
I am simply trying to call a store procedure (SQL Server 2008) using C#
I'm trying to call a stored procedure from my MVC app using EntLib 5.0.
I have an existing stored procedure in SQL Server that I need to call
So I'm trying to write a SQL Server Trigger that will call an ASP.Net
I'm trying to execute a stored procedure (against SQL Server 2005 through the ODBC
I'm having an issue trying to call a web service from stored procedure. sp_OACreate
I'm trying to retrieve the result from a stored procedure by using Hibernate in
I'm getting the error when accessing a Stored Procedure in SQL Server Server Error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.