Cenk Yurtseven
English Deutsch Türkçe
Home ASP.Net Code Library ASP.Net Code Library Database Tools Database Tools
 1  matching result

Database Creator Database Creator Language:  ASP.Net 
This ASP.NET script is for creating SQL Server Databases online and remotely through a web browser. The database is dropped if it allready exists, a new database is created on SQL Server.

Database Creator

VB Code: (you may need to modify the database file path: C:Program FilesMicrosoft SQL ServerMSSQLdata according to your SQL Server''s intallation path on your machine)

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)
Dim CreateCreateCommand As SqlCommand
Dim DropCreateCommand As SqlCommand
CreateCreateCommand = New SqlCommand("CREATE DATABASE [" & QuString & "] ON (NAME = N''" & QuString & "_Data'', FILENAME = N''C:Program FilesMicrosoft SQL ServerMSSQLdata" & QuString & "_Data.MDF'', SIZE = 1, FILEGROWTH = 10%) LOG ON (NAME = N''" & QuString & "_Log'', FILENAME = N''C:Program FilesMicrosoft SQL ServerMSSQLdata" & 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 & "'') DROP DATABASE [" & QuString & "]", myConnection)
End Try
End Sub
End Class
End Namespace
<%@ Page Language="VB" Debug="true" Src="SQLDBCreator.vb"%>
<%@ Import Namespace="SQLControlDBCreator" %>
<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
     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.")
               output.InnerHtml = (Err.Description)
          End If
          output.InnerHtml = ("Connect to your SQL Server")
     End If
End Sub
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE>SQL Server Database Creator</TITLE>
<STYLE TYPE="text/css">
BODY, TD, XMP, INPUT { FONT-FAMILY : Verdana, Arial, Tahoma; FONT-SIZE : 10pt; FONT-WEIGHT : bold }
<DIV ALIGN="center">
<FONT SIZE="+1">Create New Database</FONT>
<XMP ID="output" RUNAT="Server"/>
<FORM RUNAT="Server">
    <TD>Server IP:</TD>
    <TD><ASP:TextBox ID="ServerIP" SIZE="23" RUNAT="server"/></TD>
    <TD>User ID:</TD>
    <TD><ASP:TextBox ID="ServerAdmin" SIZE="23" VALUE="sa" RUNAT="server"/></TD>
    <TD><ASP:TextBox ID="ServerPassword" SIZE="23" RUNAT="server"/></TD>
    <TD>Database Name:</TD>
    <TD><ASP:TextBox ID="DBName" SIZE="23" RUNAT="server"/></TD>
    <TD> </TD>
    <TD><ASP:Button Text="Create Database" RUNAT="Server"/></TD>

Member Login  |  Contact Us