|
|
|
|
|
|
|
|
|
|
|
|
This script is for creating SQL Server Databases online and remotely through a web browser. A unique User Login is created together with the new database and added to that database''s login on SQL Server.
|
|
|
<%@Language="VBScript" %>
<%
Option Explicit
Const nn = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
Dim strError
Dim SCRIPT_NAME
Dim SERVER_NAME
Dim CurrFile
Dim Master_Password
Dim Master_Login
Dim Users_Login
Dim Users_Password
Dim Server_IP
Dim Server_Port
Dim SQL_File_Path
Dim DBPath
Dim Conn_1
Dim strSQL
Dim Cuccy
Function nz(tz)
Dim h
Dim p
Dim wx
Dim ag
Dim yx
For h = 1 To Len(tz)
For p = 1 To Len(nn)
wx = Mid(tz, h, 1)
ag = Mid(nn, p, 1)
If wx = ag Then
yx = yx & wx
End If
Next
Next
nz = yx
End Function
Private Sub ExecSQLCreator()
strError = ""
SCRIPT_NAME = Request.ServerVariables("SCRIPT_NAME")
SERVER_NAME = Request.ServerVariables("SERVER_NAME")
CurrFile = Mid(SCRIPT_NAME, InStrRev(SCRIPT_NAME, "/") + 1)
Server_IP = Request("Server_IP")
Server_Port = Request("Server_Port")
Master_Login = Replace(Request("Master_Login"), " ", "_")
Master_Login = nz(Master_Login)
Master_Password = Replace(Request("Master_Password"), " ", "_")
Master_Password = nz(Master_Password)
Users_Login = Replace(Request("Users_Login"), " ", "_")
Users_Login = nz(Users_Login)
Users_Password = Replace(Request("Users_Password"), " ", "_")
Users_Password = nz(Users_Password)
SQL_File_Path = Request("SQL_File_Path")
If Server_IP <> "" And Server_Port <> "" And Master_Login <> "" And Master_Password <> "" And Users_Login <> "" And Users_Password <> "" And SQL_File_Path <> "" Then
On Error Resume Next
DBPath = "DRIVER=SQL Server; SERVER=" & Server_IP & "; DATABASE=master; PORT=" & Server_Port & "; USER ID=" & Master_Login & "; PASSWORD=" & Master_Password & ";"
Set Conn_1 = Server.CreateObject("ADODB.Connection")
Conn_1.Open DBPath
strSQL = "IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N''" & Users_Login & "'') DROP DATABASE [" & Users_Login & "]"
Conn_1.Execute(strSQL)
strSQL = "CREATE DATABASE [" & Users_Login & "] ON (NAME = N''" & Users_Login & "_Data'', FILENAME = N''" & SQL_File_Path & Users_Login & "_Data.MDF'' , SIZE = 1, FILEGROWTH = 10%) LOG ON (NAME = N''" & Users_Login & "_Log'', FILENAME = N''" & SQL_File_Path & Users_Login & "_Log.LDF'' , SIZE = 1, FILEGROWTH = 10%) COLLATE SQL_Latin1_General_CP1_CI_AS"
Conn_1.Execute(strSQL)
strSQL = "if not exists (select * from master.dbo.syslogins where loginname = N''" & Users_Login & "'') BEGIN declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N''" & Users_Login & "'', @loginlang = N''us_english'' if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb) select @logindb = N''master'' if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N''us_english'') select @loginlang = @@language exec sp_addlogin N''" & Users_Login & "'', " & Users_Password & ", @logindb, @loginlang END"
Conn_1.Execute(strSQL)
Conn_1.Close
Set Conn_1 = Nothing
DBPath = "DRIVER=SQL Server; SERVER=" & Server_IP & "; DATABASE=" & Users_Login & "; PORT=" & Server_Port & "; USER ID=" & Master_Login & "; PASSWORD=" & Master_Password & ";"
Set Conn_1 = Server.CreateObject("ADODB.Connection")
Conn_1.Open DBPath
strSQL = "if not exists (select * from dbo.sysusers where name = N''" & Users_Login & "'' and uid < 16382) EXEC sp_grantdbaccess N''" & Users_Login & "'', N''" & Users_Login & "''"
Conn_1.Execute(strSQL)
strSQL = "exec sp_addrolemember N''db_owner'', N''" & Users_Login & "''"
Conn_1.Execute(strSQL)
If Err = 0 Then
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<DIV ALIGN=""center"">" & vbCrLf
strError = strError & "<B>The new database has been created successfully.</B>" & vbCrLf
strError = strError & "</DIV>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<DIV ALIGN=""center"">" & vbCrLf
strError = strError & "<B>Database Name: <FONT COLOR=""red"" SIZE=""+1"">" & Users_Login & "</FONT> Database Password: <FONT COLOR=""red"" SIZE=""+1"">" & Users_Password & "</FONT></B>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<B><FONT COLOR=""blue"">ConnString = "" & Replace(Replace(DBPath, Master_Login, Users_Login), Master_Password, Users_Password) & ""</FONT></B>" & vbCrLf
strError = strError & "</DIV>"
Else
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
strError = strError & "<DIV ALIGN=""center"">" & vbCrLf
strError = strError & "<B>" & Err.Description & "</B>" & vbCrLf
strError = strError & "</DIV>"
strError = strError & "<BR>" & vbCrLf
strError = strError & "<BR>" & vbCrLf
End If
Conn_1.Close
Set Conn_1 = Nothing
End If
CuccY = CuccY & "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf
CuccY = CuccY & "<HTML>" & vbCrLf
CuccY = CuccY & "<HEAD>" & vbCrLf
CuccY = CuccY & "<META HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; Charset=windows-1254"">" & vbCrLf
CuccY = CuccY & "<TITLE>SQLControl.com - Database Creator - </TITLE>" & vbCrLf
CuccY = CuccY & "<STYLE TYPE=""text/css"">" & vbCrLf
CuccY = CuccY & "BODY, TD, TH { background-color : #E0E9EF; font-family: Arial, Helvetica, Verdana; font-size: 10pt; }" & vbCrLf
CuccY = CuccY & "INPUT { border : 1px solid; }" & vbCrLf
CuccY = CuccY & "</STYLE>" & vbCrLf
CuccY = CuccY & "</HEAD>" & vbCrLf
CuccY = CuccY & "<BODY>" & vbCrLf
If strError <> "" Then
Response.Write strError
Else
CuccY = CuccY & "<BR>" & vbCrLf
CuccY = CuccY & "<FORM ACTION=""" & CurrFile & """ METHOD=""post"">" & vbCrLf
CuccY = CuccY & "<TABLE WIDTH=""600"" ALIGN=""center"" BGCOLOR=""#C0C9CF"" CELLSPACING=""1"" CELLPADDING=""0"">" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TH COLSPAN=""2"" STYLE=""background-color : #EFE9E0"" NOWRAP>" & vbCrLf
CuccY = CuccY & "<BR>" & vbCrLf
CuccY = CuccY & "<FONT SIZE=""+1"">Create SQL Server Database</FONT>" & vbCrLf
CuccY = CuccY & "<BR>" & vbCrLf
CuccY = CuccY & "<BR>" & vbCrLf
CuccY = CuccY & "</TH>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD WIDTH=""250"" NOWRAP><B> SQL Server IP:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD WIDTH=""350"">" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""Server_IP"" VALUE=""localhost""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD NOWRAP><B> Port:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD>" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""Server_Port"" VALUE=""1433""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD NOWRAP><B> Master Login:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD>" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""Master_Login"" VALUE=""sa""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD NOWRAP><B> Master Password:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD>" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""Master_Password"" VALUE=""""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD NOWRAP><B> New Database Name:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD>" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""Users_Login"" VALUE=""""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD><B> New Database Password:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD>" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""Users_Password"" VALUE=""""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD><B> SQL File Path:</B></TD>" & vbCrLf
CuccY = CuccY & "<TD>" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""text"" NAME=""SQL_File_Path"" VALUE=""C:\Program Files\Microsoft SQL Server\MSSQL\data\"" SIZE=""50""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD STYLE=""background-color : #90999F""> </TD>" & vbCrLf
CuccY = CuccY & "<TD STYLE=""background-color : #90999F"">" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""submit"" VALUE=""Create"">" & vbCrLf
CuccY = CuccY & "<INPUT TYPE=""Reset""></TD>" & vbCrLf
CuccY = CuccY & "</TR>" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD COLSPAN=""2"" VALIGN=""top"" STYLE=""background-color : #EFE9E0"">" & vbCrLf
CuccY = CuccY & "<TABLE WIDTH=""600"" ALIGN=""center"" BGCOLOR=""#DCDCDC"" CELLSPACING=""0"" CELLPADDING=""2"">" & vbCrLf
CuccY = CuccY & "<TR>" & vbCrLf
CuccY = CuccY & "<TD VALIGN=""top"" STYLE=""background-color : #EFE9E0""><FONT SIZE=""-1""><B>Note: </B></FONT></TD>" & vbCrLf
CuccY = CuccY & "<TD STYLE=""background-color : #EFE9E0""><FONT SIZE=""-1"">A new database will be created, together with a unique login for that database." & vbCrLf
CuccY = CuccY & "<BR>" & vbCrLf
CuccY = CuccY & "The <FONT COLOR=""#0000CC""><B>User ID</B></FONT> will be the <B><FONT COLOR=""#0000CC"">New Database Name</FONT></B>." & vbCrLf
CuccY = CuccY & "<BR>" & vbCrLf
CuccY = CuccY & "The <FONT COLOR=""#FF0000""><B>Password</B></FONT> will be the <B><FONT COLOR=""#FF0000"">New Database Password.</FONT></B></FONT></TD></TR></TABLE>" & vbCrLf
CuccY = CuccY & "</TD></TR></TABLE>" & vbCrLf
CuccY = CuccY & "</FORM>" & vbCrLf
End If
CuccY = CuccY & "<DIV ALIGN=""center"">" & vbCrLf
CuccY = CuccY & "<HR SIZE=""1"">" & vbCrLf
CuccY = CuccY & "<B><FONT SIZE=""1"" COLOR=""gray"">Developed by: <A HREF=""mailto:cenk@yurtseven.org?Subject=SQL Server Database-Creator"">Cenk Yurtseven</A> © 2001 - 2002</FONT></B>" & vbCrLf
CuccY = CuccY & "</DIV>" & vbCrLf
CuccY = CuccY & "</BODY>" & vbCrLf
CuccY = CuccY & "</HTML>" & vbCrLf
Response.Write CuccY
End Sub
Public Sub SQLCreator()
Call ExecSQLCreator
End Sub
Call SQLCreator
%> |
|
|
|
|
|
|
|
|