T-SQL stored procedure returns null in code, but works in console
Date : March 29 2020, 07:55 AM
To fix this issue I am sorry to have to say, but this might be due to using the Odbc I tried this using out SqlClient database object and it returned the values as expected. SqlCommand command = new SqlCommand("ZZZ_get_unique_identifier");
command.CommandType = CommandType.StoredProcedure;
SqlParameter return_param = new SqlParameter("@RETURN_VALUE",SqlDbType.BigInt);
return_param.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(return_param);
SqlConnection con = new SqlConnection(dbM.DefaultConnectionString);
con.Open();
command.Connection = con;
command.ExecuteNonQuery();
int i = Convert.ToInt32(command.Parameters["@RETURN_VALUE"].Value.ToString());
con.Close();
|
Stored procedure not returning value when executed from code, works fine from management studio
Date : March 29 2020, 07:55 AM
this will help Your sample works if you populate a DataSet instead of a DataTable. Here is a copy of your source with the minimum changes required. Note that when you're using a DataSet you should add code to check whether any tables were returned, and whether there are rows in the first table available, etc. SqlParameter[] Parameters = new SqlParameter[1];
Parameters[0] = new SqlParameter();
Parameters[0].ParameterName = "@TestId";
Parameters[0].Value = TestId;
Parameters[0].SqlDbType = SqlDbType.Int;
Parameters[0].Size = 50;
DataSet data = ExecuteDataSet("ExportTestAsXML", Parameters);
// Read First table (Tables[0]), First Row (Rows[0]), First Column of that Row (Rows[0][0])
System.Diagnostics.Debug.Write(data.Tables[0].Rows[0][0]);
private DataSet ExecuteDataSet(string storedProcName, SqlParameter[] parameters)
{
SqlCommand command = new SqlCommand();
command.CommandText = storedProcName;
command.Parameters.AddRange(parameters);
command.CommandType = CommandType.StoredProcedure;
command.Connection = (SqlConnection)dcMUPView.Connection;
command.Connection.Open();
command.Prepare();
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet ();
adapter.Fill(ds);
command.Connection.Close();
return ds;
}
|
Stored Procedure works in Mysql workbench but not in C# code
Tag : chash , By : CrimsonGore
Date : March 29 2020, 07:55 AM
I hope this helps you . I have a stored procedure which I want to delete and then want to re-create it. It is working from Mysql workbench but not working from c# code. , I found a solution and it is working perfectly. C# Code: string myConnectionString = FetchDbConnectionString(environment, item);
MySqlConnection mySqlConnection = new MySqlConnection(myConnectionString);
const string sqlQuery ="DELIMITER $$ DELIMITER $$ DROP PROCEDURE IF EXISTS AccountGetAccountOpeningClosingStock; $$ CREATE PROCEDURE AccountGetAccountOpeningClosingStock(IN _endDate datetime) BEGIN Select * From tutorials_tbl Where CreateDate <= _endDate order by CreateDate asc; END$$ $$ DELIMITER; DELIMITER;";
MySqlScript script = new MySqlScript();
script.Connection = mySqlConnection;
script.Query = sqlQuery;
script.Execute();
mySqlConnection.Close();
|
Getting out parameter of stored procedure with C# only works when I put a breakpoint in my code
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Output parameters are not available until the return result has been read completely, or the underlying DbDataReader is closed. See the Parameters section of ObjectContext.ExecuteFunction, and the second sentence of this section on DataReaderspublic static Guid AddProfesseur(string prenom, string nom)
{
using (ExamenProjetIntegrationEntities db = new ExamenProjetIntegrationEntities())
{
ObjectParameter objParam = new ObjectParameter("identity", typeof(Guid));
var resultToReturn = db.AjouterProfesseur(prenom, nom, objParam).Count();
return Guid.Parse(objParam.Value.ToString());
}
}
|
Stored procedure keeps running - code works fine executed outside of the stored procedure
Tag : sql , By : Joe Sweeney
Date : March 29 2020, 07:55 AM
this will help Global temporary tables are visible from multiple sessions, but they have locking just like regular tables. So sessions can't read each other's uncommitted changes. This includes uncommitted DDL, like CREATE TABLE or SELECT ... INTO. What you have is a un-detectable deadlock between your sessions, equivalent to: begin transaction
create table ##t(id int)
exec xp_cmdshell 'bcp "select * from ##t" queryout "c:\temp\foo.csv" -S "localhost" -T'
|