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! | Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
| | | | XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. FREE! Go There Now!
| | | | As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
| | | | Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
| | | | Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
| | | | In this webcast, IBM Rational will discuss the importance of Web application security and will share techniques and best practices to introduce application security testing into current QA processes including: understanding common security vulnerabilities and techniques to integrate security testing with defect tracking and remediation systems in an effort to safeguard sensitive online information. FREE! Go There Now!
| | | | The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
| | | | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |