-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrations: Handle GO statements in SQL Server #6747
Comments
What is the error you are getting? |
The error we are getting is below. I have also included below a sample script. The real script attempts to create about 80 separate stored procedures which is why we need the GO statements. ERROR: Incorrect syntax near the keyword 'PROCEDURE'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action SAMPLE SCRIPT
|
@patricknolan - Thanks for additional info. I tried running above script and I indeed hit error that |
Thanks for the response. I removed the last GO and it still fails with the following error. If I remove the first GO aswell it works. However, to create multiple stored procedures I need to include the GO statement. Any ideas why it is working for you and not me? Incorrect syntax near the keyword 'PROCEDURE'. |
@patricknolan - I got it running because I had removed starting Running following piece of code in console app also throws same exception. var myConnection = new SqlConnection(@"Server=(localdb)\mssqllocaldb;Database=_ModelApp;Trusted_Connection=True;");
myConnection.Open();
var command = new SqlCommand(File.ReadAllText("Data.sql"), myConnection);
command.ExecuteNonQuery(); Exception:
It seems that underlying SqlClient is not able to handle it. EF just passes content of sql after appending The same sql works fine if run directly into SqlServer Management Studio. |
Do you know if there's an alternative recommended approach? I would have thought running a SQL script post the migration UP routine to create some stored procedures would be a fairly common requirement. |
GO is just tooling sugar for starting a new command. You should be able to work around this be splitting at the GO statements and putting the parts into their own Sql call. We did this for you in EF6. We should consider adding it to EF Core. |
Note to implementer: Here is the code for handling utility statements in EF6. |
I need to run a separate sql script just after the migration Up logic is executed.
The following sample works fine, except the script is creating quite a few Stored Procedures etc which requires the use of GO statements.
However, the MigrationBuilder.Sql does not seem to support the GO statement. I haven't tried splitting into multiple script files but I would rather not do this as I would require a lot.
Is this something which will be supported soon. What would be the best workaround for the moment?
The text was updated successfully, but these errors were encountered: