July 16, 2008 at 12:47 pm
I have a C# extended stored procedure. when I try to open the context connection, I get the error message:
“The ConnectionString property has not been initialized.“
at System.Data.SqlClient.SqlConnection.PermissionDemand()
at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()”
here is the code :
using (SqlConnection connection = new SqlConnection("context connection=true")) ;
{
connection.Open(); // the error occur at this line
command = new SqlCommand(Proc, connection); //these command execute a stored procedure
command.CommandType = System.Data.CommandType.StoredProcedure;
}
This code is not on the same assembly of extended stored procedure. That is, the extended stored procedure calls a class for access connection from other assembly. That design is strongly needed by the project and I cant change it , so the two assemblies are referenced in the database and they have Unsafe permission.
Some body has any idea?
July 16, 2008 at 7:13 pm
What are you doing in the procedure before the connection portion you show here? It is almost impossible to look at this small a piece of code and offer ideas.
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
July 17, 2008 at 7:43 am
Ok...let me explain more details..
I have a class for manage connection to database and the execution of stored procedure (not the extended stored procedure), this class belong to an assembly call stored_procedures.dll.
this is the class:
public class StoredProcedure
{
private SqlCommand comand;
public StoredProcedure(string SProcname)
{
using (SqlConnection connection = new SqlConnection("context connection=true")) ;
{
connection.Open();// exception is raised at this line
comand = new SqlCommand(SProcname, connection);
comand.CommandType = System.Data.CommandType.StoredProcedure;
}
}
public DataTable Execute(SqlParameter[] parameters)
{
SqlDataAdapter adaptador = new SqlDataAdapter();
DataTable table = new DataTable();
adaptador.SelectCommand = comand;
try
{
adaptador.Fill(table);
}
catch (SqlException sqlex)
{
throw RootException.Create(sqlex.Number, sqlex.Message);
}
return table;
}
}
in the same assembly, I have a child class from this above.
public class Select_TestFromProcess: StoredProcedure
{
public Select_TestFromProcess ()
: base("get_TestFromProcess") { } //this is the name of the stored procedure
public DataTable Execute(string ProcessName)
{
SqlParameter[] parameters = new SqlParameter[1];
parameters [0] = new SqlParameter("@namePro", ProcessName);
return Execute(parameters);
}
}
The extend stored procedure that I use , is in other assembly called model.dll
This method create an Select_TestFromProcess object and call the Execute method
[Microsoft.SqlServer.Server.SqlProcedure]
public static void ExecuteProcess(string process)
{
try
{
stored_procedures . Select_TestFromProcess proc_class = new stored_procedures . Select_TestFromProcess ();
DataTable query_test = proc_class.Execute(process);
foreach (DataRow test in query_test.Rows )
{//do something}
}
catch (Exception e)
{
string msg = e.Message + e.StackTrace;
throw new ModelException(msg);
}
}
The exception is raised when I try to open connection in StoredProcedure class constructor.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy