How to Create DB in SQL server
-
Dear friends, i have some problems like i need to create application , that "creates Database,Table,Views" and need to insert default values. at first i have created script file which contains all the operation, then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed. is it possible to create the DB,Tables, View in any other way ?? Thank you
-
Dear friends, i have some problems like i need to create application , that "creates Database,Table,Views" and need to insert default values. at first i have created script file which contains all the operation, then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed. is it possible to create the DB,Tables, View in any other way ?? Thank you
-
You can keep your scripts in .sql files and then execute them using ADO.Net through the code.
Thanks....for reply i got info form [^]
-
Dear friends, i have some problems like i need to create application , that "creates Database,Table,Views" and need to insert default values. at first i have created script file which contains all the operation, then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed. is it possible to create the DB,Tables, View in any other way ?? Thank you
Hi!! You can execute them using the .NET Sql or OleDB connector. Something like this will work System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection([ConnectionString]); cnn.Open(); using (System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand([query], cnn)) { Command.ExecuteNonQuery(); Command.Dispose(); cnn.Close(); cnn.Dispose(); } Obviously if you are going to execute a bunch of query because you're going to create all the tables, insert all the defaults and such in the same process you should use transactions. Information about how to do that can be found in the MSDN, you only need to add a couple of lines more. Hope this helps :)