Solved

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

Posted on 2011-03-16
6
272 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

11 Experts available now in Live!

Get 1:1 Help Now