I am trying to Execute python script from my .Net Web Application. For this I have installed Python from nuget package manager. But I am getting following errors during execution:
I have attempted following code chunks for getting resolution but I am not able to execute it successfully.
Below is the Python Scrip to Insert a record in SQL Server database:
import pyodbc
conn = pyodbc.connect('DRIVER={SQL Server Native Client
11.0};SERVER=*****\SQLEXPRESS;DATABASE=TestDB;UID=sa;PWD=****')
cur = conn.cursor()
cur.execute("Insert into Results([EmailID],[Journey]) VALUES (?,?)", 55,
"JourneyName")
conn.commit()
Print("Success")
Below is the C# Code to execute above python file.
public string run_cmd(string strPath) //this must not be async
{
try
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Anaconda\python.exe";
start.Arguments = string.Format("C:\\Users\\261866\\TestPYCode.py");
start.UseShellExecute = false;
start.CreateNoWindow = true;
start.RedirectStandardOutput = true;
start.RedirectStandardError = true;
using (Process process = Process.Start(start))
{
using (StreamReader reader = process.StandardOutput)
{
string stderr = process.StandardError.ReadToEnd();
string result = reader.ReadToEnd();
return result;
}
}
}
catch (Exception ex)
{
return ex.Message;
}
return "run till end";
}
As I have executed above c# code I am getting below Error:
Traceback (most recent call last):"C:\Users\261866\TestPYCode.py" import pyodbc Module Not Found Error: No module named 'pyodbc'
Error: No module named 'pyodbc'
pyodbcinstall errors, or edit this and make the installation errors as the primary ask.