• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

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.
0
PHYSIVERT
Asked:
PHYSIVERT
1 Solution
 
DhaestCommented:
Create database in sql server using asp.net with C# (VS2005)
http://www.codeproject.com/KB/aspnet/Create_Database.aspx

Create SQL Server Database using asp.net
http://www.codeproject.com/KB/aspnet/SQLDb_Using_Aspnet.aspx

How to execute an .SQL script file using c#
http://stackoverflow.com/questions/650098/how-to-execute-an-sql-script-file-using-c

How to Execute a SQL Script or Query From an ASP.NET Website
http://www.brighthub.com/internet/web-development/articles/9410.aspx
0
 
Ryan ChongCommented:
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.
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hi, try this code

using System.Data.SqlClient;

using System.IO;

using Microsoft.SqlServer.Management.Common;

using Microsoft.SqlServer.Management.Smo;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            string sqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True";

            FileInfo file = new FileInfo("C:\\myscript.sql");

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

            SqlConnection conn = new SqlConnection(sqlConnectionString);

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

            server.ConnectionContext.ExecuteNonQuery(script);

        }

    }

}
0
 
Amandeep Singh BhullarCommented:
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.
0
 
DhaestCommented:
My recommandations: Accept my answer (#35154359). It's a very general question and with the link's provided the question can be solved
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now