gk.powersuche.org

Siehe auch:

ASP.Net
Dieser Code erstellt eine neue Datenbank auf dem SQL Server

Bitte kontaktieren Sie uns, falls Sie spezielle praktische Scripts brauchen, um Ihre Arbeit zu erleichtern.


VB Code: (Sie müssen eventuell den Pfad verändern: "C:ProgramFilesMicrosoft SQL ServerMSSQLdata" entsprechend Ihrem Intallations Pfad und diesen Code speichern als: SQLDBCreator.vb)

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 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)
myConnection.Open()
DropCreateCommand.ExecuteNonQuery()
CreateCreateCommand.ExecuteNonQuery()
Finally
myConnection.Close()
End Try
End Sub
End Class
End Namespace


Die Asp.Net Datei:

<%@ 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
          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
</SCRIPT>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<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 }
</STYLE>
</HEAD>
<BODY>
<BR>
<DIV ALIGN="center">
<FONT SIZE="+1">Create New Database</FONT>
<BR>
<BR>
<BR>
<XMP ID="output" RUNAT="Server"/>
<FORM RUNAT="Server">
<TABLE ALIGN="center" WIDTH="60%" CELLSPACING="1" CELLPADDING="2" BORDER="0">
<TR>
    <TD>Server IP:</TD>
    <TD><ASP:TextBox ID="ServerIP" SIZE="23" RUNAT="server"/></TD>
</TR>
<TR>
    <TD>User ID:</TD>
    <TD><ASP:TextBox ID="ServerAdmin" SIZE="23" VALUE="sa" RUNAT="server"/></TD>
</TR>
<TR>
    <TD>Password:</TD>
    <TD><ASP:TextBox ID="ServerPassword" SIZE="23" RUNAT="server"/></TD>
</TR>
<TR>
    <TD>Database Name:</TD>
    <TD><ASP:TextBox ID="DBName" SIZE="23" RUNAT="server"/></TD>
</TR>
<TR>
    <TD> </TD>
    <TD><ASP:Button Text="Create Database" RUNAT="Server"/></TD>
</TR>
</TABLE>
</FORM>
</DIV>
</BODY>
</HTML>



Haben Sie schon mal daran gedacht, eine eigene Suchmaschine zu besitzen, die Ihrem Unternehmen täglich hunderte von Besuchern schickt?
Eine Neue Epoche

Free Downloads




gk.powersuche.org

© 2024 GK Dienstleistungs UG

Cookies

Diese Website benutzt Cookies, um Ihnen ein besseres Weberlebnis zu garantieren.