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 developerWorks - FREE Tools! | 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!
| | | | 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!
| | | | 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!
| | | | 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!
| | | | 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!
| | | | 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!
| | | | 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!
| | | | 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!
| | | | 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!
| | | | 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! | |