Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've built this little stored procedure peice of code however when I run it it comes up with the error
"Cannot open database "Sales" requested by the login. The login failed Login failed for user 'MASTER\MyName'."
I know for a fact that the code works on another database with diffrent inputs but not this one. Im using the example from this Introducing Distributed Messaging using Service Broker in SQL Server 2005[^] i've just changed the variables slightly and have tried to run the stored procedure through my C# app. In the example it sets
SQL
CREATE MASTER KEY
ENCRYPTION BY PASSWORD = 'hellopassword';
GO

I'm not sure if that makes a difference. Anyway below is my C# please help!
SqlConnection conn = null;
          SqlDataReader rdr = null;

          string orderinfo = richTextBox1.Text;

          try
          {
              conn = new SqlConnection(
                  "Server=(local);DataBase=Sales;Integrated Security=SSPI");
              conn.Open();

              SqlCommand cmd = new SqlCommand("runorder", conn);

              cmd.CommandType = CommandType.StoredProcedure;

              cmd.Parameters.Add(new SqlParameter("@order", orderinfo));

              rdr = cmd.ExecuteReader();

          }
          finally
          {
              if (conn != null)
              {
                  conn.Close();
              }
              if (rdr != null)
              {
                  rdr.Close();
              }
          }


P.S Under the user mapping for the security of MASTER\MyName the user is set to 'dbo' and has the permissions of database owner.
Posted
Updated 10-Jan-12 8:25am
v2

 
Share this answer
 
v2
Comments
WurmInfinity 10-Jan-12 14:33pm    
Already tried this, as explain in the P.S bit at the bottom the user is already the database owner...
thatraja 10-Jan-12 14:54pm    
Check updated answer & let me know
WurmInfinity 10-Jan-12 15:14pm    
urrmmmmmmmm ok so I set it up with SQL authentication instead. What ADO do I use to connect in through that way?
thatraja 10-Jan-12 15:16pm    
:Doh: Still you are getting the same error?
WurmInfinity 10-Jan-12 15:21pm    
yes I am.
Few things to check (may contain things you've already done)
- the sql server is part of the same domain (master)
- your user is listed in sql server logins (or one of the groups you belong to)
- the login from previous step is defined as a database user in the database
- the login isn't disabled
- the user isn't disabled in the database

Also to make sore that connection works at all try connecting using SQL Server authentication (just a test, not a permanent solution)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900