[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-03-16
6
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 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 53

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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