Solved

Executing database script (includes creating new database ,stored procedure) through Programming in ASP.NET

Posted on 2011-03-16
6
261 Views
Last Modified: 2012-05-11
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
Comment
Question by:PHYSIVERT
6 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 35154359
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 35154392
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
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 35155738
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
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 37254428
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 37254429
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now