Hello,
I have an SQL script in a file that I want to execute through a .NET 6 application, processing it line by line. The script begins with the command "USE [INVOICES]." However, when I launch the application, I get the following error message:
"System.Data.SqlClient.SqlException: 'Incorrect syntax near ''.' "
The line causing the error is the first line "USE [INVOICES]"
Here is the C# code I am using:
the value of sql variable is "USE [INVOICES]"
using (SqlCommand comm = new SqlCommand(sql, cn))
{
if (comm.Connection.State != ConnectionState.Open)
comm.Connection.Open();
comm.CommandTimeout = this.sqlCommandTimeout;
comm.ExecuteNonQuery();
}
Do you have any suggestions for resolving this issue?
Thank you in advance.