0

I get the error:

Azure SQL Database: [SqlException (0x80131904): Could not find stored procedure

when I deploy my ASP.NET MVC application to azure. My database is an Azure SQL database.

The code runs fine in my development environment. The procedure belongs to a custom schema. Below is how I call the procedure from my code.

SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[schema_name].[procedure_name]";

I think it might have to do with some schema permission. I took the connection string to connect my mvc application to DB from the azure protal.

I would really appreciate any help/direction.

Ravi Kukreja
  • 627
  • 1
  • 8
  • 17
  • The error is pretty clear - you are either connecting to the wrong database, or the stored procedure doesn't exist. – Dale K Aug 18 '20 at 00:35
  • @DaleK Thanks for the response. The clear error adds to my confusion. The exact code runs in my development machine and throws the error when deployed to Azure. The Procedure exists and I am connecting to the correct DB. – Ravi Kukreja Aug 18 '20 at 00:39
  • Can you connect to the same database, using the same connection string and login, using ssms and run the same stored proc? – TomC Aug 18 '20 at 00:57
  • @TomC Yes, I connected to ssms and ran the procedure ``exec [schema_name].[procedure_name] 'param'`` – Ravi Kukreja Aug 18 '20 at 01:07
  • This sort of problem is going to require you to carry out a thorough investigation... with the information provided there is no way anyone can actually answer for you. You have to confirm that your published app is connecting to the correct database, that the correct database has that SP, and that your app is connecting as a user which has permissions to run that SP (permissions are very important). Also ensure your scheme_name is consistent obviously. You're just going to have to go on a mission to hunt it down - after all, thats why they pay you the big bucks :) – Dale K Aug 18 '20 at 01:16
  • Can you write 'cmd.CommandText = "[schema_name].[procedure_name]";' before cmd.CommandType and then check? You are passing SP name after declaring the type of the command which is incorrect. This may not make sense but you can check atleast :P – Rohan Rao Aug 18 '20 at 05:35
  • Pls check your sql connections in your `web.config`, or in portal. If your webapp can connect to azure sqlserver, I think you have permission to excute your procedure. https://stackoverflow.com/questions/61644033/net-core-on-azure-cant-connect-to-sql-server-database/61650563#61650563 – Jason Pan Aug 20 '20 at 08:00

0 Answers0