Hi everybody.
Im trying to call the sproc 'sp_setapprole' with the esUtility class. After that i want to check if it was set correctly, so i execute 'Select User_Name()'.
First heres the code:
Code:
esUtility esUtil = new esUtility();
esParameter name = new esParameter("rolename", m_appRoleName);
esParameter pwd = new esParameter("password",txtPwd.Text);
esParameter cookieCreate = new esParameter("fCreateCookie", true);
esParameter cookieOut = new esParameter("cookie",esParameterDirection.Output,DbType.Binary, 8000);
esParameters sqlParams = new esParameters();
sqlParams.Add(name);
sqlParams.Add(pwd);
sqlParams.Add(cookieCreate);
sqlParams.Add(cookieOut);
esUtil.ExecuteReader(esQueryType.StoredProcedure, "sp_setapprole", sqlParams);
System.Data.IDataReader idr = esUtil.ExecuteReader(esQueryType.Text, "SELECT USER_NAME()");
if (idr.Read())
{
System.Console.WriteLine(idr.GetString(0));
}
What happens is that everything seems to do ok, but 'Select User_Name()' always returns just 'dbo'. It should return the name of the application role. If i enter a wrong password i get an SqlException, so it seems if i enter the correct password the sproc itself runs without failure.
If i do the same thing without EntitySpaces it works:
Code:
SqlCommand com = sqlConn.CreateCommand();
com.Parameters.Add(new SqlParameter("rolename", "LD23"));
com.Parameters.Add(new SqlParameter("password", "ld23!"));
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "sp_setapprole";
com.ExecuteNonQuery();
comSelect = sqlConn.CreateCommand();
comSelect.CommandType = CommandType.Text;
comSelect.CommandText = "Select User_Name()";
SqlDataReader sdr = comSelect.ExecuteReader();
if (sdr.Read())
{
System.Console.WriteLine(sdr[0].ToString());
}
sdr.Close();
Some other strange things:If i use 'ExecuteNonQuery' for calling the sproc i get an SqlException when i try to select the username, the sproc itself runs. 'A severe error occurred on the current command. The results, if any, should be discarded.'.
If i don´t try to get the username, i get this error at the next 'Database-Action'.
Sometimes i get this error even when using 'ExeceuteReader' at the next 'Database-Action' after selecting the(wrong) username. This Exception never causes a crash(I can re-run the command causing it, it works the second time), and the results i get seem ok(except the wrong user name).I assume this may have something to do with Sql-Connections and the way ES handles them, but im not sure at all. Any suggestions appreciated :)
Bye,
Joris