PHYSIVERT
asked on
Executing database script (includes creating new database ,stored procedure) through Programming in ASP.NET
I want to make a new database using sql script in c# where it includes database name,Stored Procedure and tablle with its defaults data that I want to fill.How can I do that using C# in Asp.NET.
Is there any way that I can accomplish this asap.Please guide me.
Is there any way that I can accomplish this asap.Please guide me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps the easy way out is write all your scripts into a Stored Procedure, then establish a connection from ASP.NET to execute that SP.
Hi, try this code
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Manage ment.Commo n;
using Microsoft.SqlServer.Manage ment.Smo;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Int egrated Security=True";
FileInfo file = new FileInfo("C:\\myscript.sql ");
string script = file.OpenText().ReadToEnd( );
SqlConnection conn = new SqlConnection(sqlConnectio nString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.E xecuteNonQ uery(scrip t);
}
}
}
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Manage
using Microsoft.SqlServer.Manage
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Int
FileInfo file = new FileInfo("C:\\myscript.sql
string script = file.OpenText().ReadToEnd(
SqlConnection conn = new SqlConnection(sqlConnectio
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.E
}
}
}
I've requested that this question be deleted for the following reason:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
My recommandations: Accept my answer (#35154359). It's a very general question and with the link's provided the question can be solved