Hi i am working on a system for a client and they ahve recently asked me to change from SQL Server Authentication to Windows Authentication. I have set this up in the database (SQL Server 2008 using SSMS) and i can access the database by using my windows login.
The problem i am having is when i am rubbing the code (eithe locally or on the server). When i try to run the code it is breaking everytime i access a stored procedure saying "Could not find stored procedure". I think the reason for this is because within my atabase most of the stored procedures have a schema prefix. (e.g. MySchema.MyStoredProc). Within the code the schema prefix is not added to the start of the procedure name (and this would not be possible to change as there are thousands of calls to stored procs).
What i would like to know, is there any way of adding some code so that the .net code looks uo the Schema prefix?
I have looked online and it says this is possible within SSMS but i canot seem to get it to work and would be a much easier fix if i could chnage it from the .NET code.
Here is my connection string:
<add key="DatabaseConnectionString" value="Data Source=DATASOURCENAME;Initial Catalog=MYDATABASE;Integrated Security=true;"/>
Any help on this would be great.
Thanks
Code Breaking due to Windows Authentication
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Jul 10, 2012, 2:34 AM EDT
1) Are you getting this error after the changing the authentication mode?
2) How you're generating/creating the instance for the command object ? It is single method is returning the command object or each database calls, you're generating the command object.
If it is a single method then,
SQLCommand cmd = new SQLCommand();
cmd.CommandType=COmmandType.Procedure.
if (cmd.CommandType == CommandType.Procedure)
{
cmd.CommandText="yourSchemaName." + ActualSPName;
}
Glen Robson27 pointsPosted Jul 10, 2012, 2:40 AM EDT
SqlCommand cmd = new SqlCommand("PKG_TEST$PR_GET_ITEST", databaseConnection);
I am not able to go through and change every time the code calls a procedure as there are thousands.
And yes this has just started happening because i changed the authentication to Windows authentication.