<%@ 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