Database Code
  Home arrow Database Code arrow SQL Server Database Creator - .NET Version
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

SQL Server Database Creator - .NET Version
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 25
    2003-01-01

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    This code demonstrates a SQL Server Database Creator class called SQLDBCreator for .Net.
    <%@ Page Language="VB" Debug="true" Src="SQLDBCreator.vb"%>
    <%@ Import Namespace="SQLControlDBCreator" %>
      Imports System.Data Imports System.Data.SqlClient Namespace SQLControlDBCreator Public Class SQLDBCreator Public Sub Run(ByRef QuString As String, ByRef CnString As String) Dim myConnection As SqlConnection myConnection = New SqlConnection(CnString) Try Dim CreateCreateCommand As SqlCommand Dim DropCreateCommand As SqlCommand CreateCreateCommand = New SqlCommand("CREATE DATABASE [" & QuString & "] ON & _ (NAME = N'" & QuString & "_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\" & _ QuString & "_Data.MDF', SIZE = 1, FILEGROWTH = 10%) LOG ON (NAME = N'" & QuString & "_Log', & _ FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\" & _ QuString & "_Log.LDF', SIZE = 1, FILEGROWTH = 10%)
    COLLATE SQL_Latin1_General_CP1_CI_AS", myConnection) & _
    DropCreateCommand = new SqlCommand("IF EXISTS (SELECT name FROM master.dbo.sysdatabases & _ WHERE name = N'" & QuString & "') myConnection.Open() DropCreateCommand.ExecuteNonQuery() CreateCreateCommand.ExecuteNonQuery() Finally myConnection.Close() End Try End Sub End Class End Namespace <SCRIPT Runat="Server"> Private Const CharChars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" Private Function CharsOnly(ByVal strChars As String) Dim i As Integer Dim j As Integer Dim wx As String Dim ag As String Dim yx As String For i = 1 To Len(strChars) For j = 1 To Len(CharChars) wx = Mid(strChars, i, 1) ag = Mid(CharChars, j, 1) If wx = ag Then yx = yx & wx End If Next Next CharsOnly = yx End Function Protected Sub Page_Load(Src As object, E As EventArgs) Dim ServerIP As String = Request.Params("ServerIP") Dim ServerAdmin As String = Request.Params("ServerAdmin") Dim ServerPassword As String = Request.Params("ServerPassword") Dim QueryString As String = CharsOnly(Request.Params("DBName")) On Error Resume Next If QueryString <> "" And ServerIP <> "" And ServerAdmin <> "" And ServerPassword <> ""
    Then Dim ConnString As String = "server=" & ServerIP & "; user id=" & ServerAdmin & _ "; password=" & ServerPassword & "; Database=master;" Dim mySQLDBCreator As SQLDBCreator mySQLDBCreator = new SQLDBCreator() mySQLDBCreator.Run(QueryString, ConnString) If Err.Number = 0 Then output.InnerHtml = ("Database Successfully created.") Else output.InnerHtml = (Err.Description) End If Else output.InnerHtml = ("Connect to your SQL Server") End If End Sub

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Database Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Push RSS to new limits

    This tutorial presents an innovative use of the well-known Really Simple Syndication (RSS) format's associative properties to emulate the functionality of a simple relational database. It demonstrates using RSS channels to store contact information and meeting information -- much as a personal address book and calendar does. It uses RSS elements and attributes such as items and guids to create a neural-network-like mesh of related data.
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    NEW! LPI exam 301 prep, Topic 302: Installation and development

    In this tutorial, Sean Walberg helps you prepare to take the Linux Professional Institute Senior Level Linux Professional (LPIC-3) exam. In this second in a series of six tutorials, Sean walks you through installing and configuring a Lightweight Directory Access Protocol (LDAP) server, and writing some Perl scripts to access the data. By the end of this tutorial, you'll know about LDAP server installation, configuration, and programming.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Write REST services

    This tutorial discusses the concepts of REST and the Atom Publishing Protocol (APP) and shows how they apply to services. It also shows how to use Java technology to implement REST/APP-based services.
    FREE! Go There Now!


    NEW! Application development for the OLPC laptop

    The XO laptop (of the One-Laptop-Per-Child initiative) is an inexpensive laptop project intended to help educate children around the world. The XO laptop includes many innovations, such as a novel, inexpensive, and durable hardware design and the use of GNU/Linux as the underlying operating system. The XO also includes an application environment written in Python with a human interface called Sugar, accessible to everyone (including kids). Explore the Sugar APIs and learn how to develop and debug a graphical activity in Sugar using Python.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway