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

i am try to run sql script from c# windows form and this error occurred

an exception occurred while executing a transact-sql statement or batch

and this the code

C#
string sqlConnectionString = BuildeConnectionString();

            FileInfo file = new FileInfo(Application.StartupPath + @"\DBScript\Database_generate.sql");

            string script = file.OpenText().ReadToEnd();

            SqlConnection conn = new SqlConnection(sqlConnectionString);

            Server server = new Server(new ServerConnection(conn));

            server.ConnectionContext.ExecuteNonQuery(script );
            
            file.OpenText().Close();


and the error occurred in this line
server.ConnectionContext.ExecuteNonQuery(script );
Posted

1 solution

can you use command object somewhat like this....

cmd.Connection = conn;
cmd.CommandText =  script
cmd.CommandTimeout = 15;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery()
 
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