I am trying to execute a sql script read from a file; however, when I go to execute the script I am met with the exception:
Column, parameter, or variable #1: Cannot find data type dbo.ExistingTableType.
Must declare the table variable "@existingTableType".
Parameter or variable '@existingTableType' has an invalid data type.
I have tried testing the script by copying the text and running it in SQL server management studio and it does run successfully. Additionally, other scripts are able to run but for some reason those with a user-defined table type as a parameter are not. Below is a simple example:
C#
string script = scriptFile.OpenText().ReadToEnd();
SqlConnection connection = new SqlConnection(connectionString);
Server server = new Server(new ServerConnection(connection));
server.ConnectionContext.StatementTimeout = 100;
server.ConnectionContext.ExecuteNonQuery(script);
SQL
CREATE PROCEDURE [dbo].[failedStoredProcedure]
(
@existingTableType dbo.ExistingTableType READONLY
)
AS
-- Do something here
GO
Other tests done:
- Tried another user in connection string.
Edit: Additionally, when scripts run it returns 'Invalid Object Name {x}' when the object does exist.