G
Guest
I am trying to execute the following stored procedure:
sp_help_job on msdb on a SQL Server 2000 installation under the context of a
user that is just a standard sql server login. Not a sysadmin.
If i run it under the context of a sysadmin i get results. However, if i run
it under a basic user i get:
A severe error occurred on the current command. The results, if any, should
be discarded.
I thought it might be related to not specifying parameters but i did that
too. Here is my code:
public void ThisWillFail()
{
string connectionString = "Data Source=server;Initial
Catalog=msdb;Integrated Security=false;User
ID=basicuser;Password=basicuser;Application Name=TESTAPP;Persist Security
Info=False;Connect Timeout=30;";
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand("sp_help_job", sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("@job_id", SqlDbType.UniqueIdentifier);
sqlCommand.Parameters.Add("@job_name", SqlDbType.NVarChar, 128);
sqlCommand.Parameters.Add("@job_aspect", SqlDbType.VarChar, 9);
sqlCommand.Parameters.Add("@job_type", SqlDbType.VarChar, 12);
sqlCommand.Parameters.Add("@owner_login_name", SqlDbType.NVarChar, 128);
sqlCommand.Parameters.Add("@subsystem", SqlDbType.NVarChar, 40);
sqlCommand.Parameters.Add("@category_name", SqlDbType.NVarChar, 128);
sqlCommand.Parameters.Add("@enabled", SqlDbType.TinyInt);
sqlCommand.Parameters.Add("@execution_status", SqlDbType.Int);
sqlCommand.Parameters.Add("@date_comparator", SqlDbType.Char, 1);
sqlCommand.Parameters.Add("@date_created", SqlDbType.DateTime);
sqlCommand.Parameters.Add("@date_last_modified", SqlDbType.DateTime);
sqlCommand.Parameters.Add("@description", SqlDbType.NVarChar, 512);
SqlDataReader dr = null;
try
{
sqlConnection.Open();
dr = sqlCommand.ExecuteReader();
while (dr.Read())
{
System.Diagnostics.Debug.WriteLine(dr["name"]);
}
}
catch (SqlException ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
finally
{
if (dr != null && !dr.IsClosed)
{
dr.Close();
}
if (sqlConnection.State == ConnectionState.Open)
{
sqlConnection.Close();
}
}
}
Any help is greatly appreciated.
-Brooke
sp_help_job on msdb on a SQL Server 2000 installation under the context of a
user that is just a standard sql server login. Not a sysadmin.
If i run it under the context of a sysadmin i get results. However, if i run
it under a basic user i get:
A severe error occurred on the current command. The results, if any, should
be discarded.
I thought it might be related to not specifying parameters but i did that
too. Here is my code:
public void ThisWillFail()
{
string connectionString = "Data Source=server;Initial
Catalog=msdb;Integrated Security=false;User
ID=basicuser;Password=basicuser;Application Name=TESTAPP;Persist Security
Info=False;Connect Timeout=30;";
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand("sp_help_job", sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("@job_id", SqlDbType.UniqueIdentifier);
sqlCommand.Parameters.Add("@job_name", SqlDbType.NVarChar, 128);
sqlCommand.Parameters.Add("@job_aspect", SqlDbType.VarChar, 9);
sqlCommand.Parameters.Add("@job_type", SqlDbType.VarChar, 12);
sqlCommand.Parameters.Add("@owner_login_name", SqlDbType.NVarChar, 128);
sqlCommand.Parameters.Add("@subsystem", SqlDbType.NVarChar, 40);
sqlCommand.Parameters.Add("@category_name", SqlDbType.NVarChar, 128);
sqlCommand.Parameters.Add("@enabled", SqlDbType.TinyInt);
sqlCommand.Parameters.Add("@execution_status", SqlDbType.Int);
sqlCommand.Parameters.Add("@date_comparator", SqlDbType.Char, 1);
sqlCommand.Parameters.Add("@date_created", SqlDbType.DateTime);
sqlCommand.Parameters.Add("@date_last_modified", SqlDbType.DateTime);
sqlCommand.Parameters.Add("@description", SqlDbType.NVarChar, 512);
SqlDataReader dr = null;
try
{
sqlConnection.Open();
dr = sqlCommand.ExecuteReader();
while (dr.Read())
{
System.Diagnostics.Debug.WriteLine(dr["name"]);
}
}
catch (SqlException ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
finally
{
if (dr != null && !dr.IsClosed)
{
dr.Close();
}
if (sqlConnection.State == ConnectionState.Open)
{
sqlConnection.Close();
}
}
}
Any help is greatly appreciated.
-Brooke