Solved

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

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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