SQL Server Database Creator - .NET Version

This code demonstrates a SQL Server Database Creator class called SQLDBCreator for .Net.

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 28
January 01, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
<%@ 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
blog comments powered by Disqus
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...
- Two combos, one textbox example
- ADO Recordset Paging
- SQL Server Database Creator - .NET Version
- Getting A List of Tables From SQL Server
- Discussion & Listserv Module by Mike Eck...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials