Hello,
I have a script that I use for a newsletter. It uses an Access database. Well, now I changed web hosts, and I need to convert it so that it will use an SQL database. I know most of what I need to do, and I even already have the database converted over to SQL, I just need to figure out how to get the script to connect to the SQL database.
First off, I know that I need to change the line that the access database connects to to;
connect_string = "Driver={Mysql}; Server=localhost; Database=testDB; UID=testUser; PWD=testUserPass"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open(connect_string)
I believe I am replacing just this line from what I have been told;
Conn.Open "DBQ=" & Server.MapPath("newsletter.mdb")& ";Driver={Microsoft Access Driver (*.mdb)}"
Here is the code for one of the files.
-----------------------------------------------------------------
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 100
Response.AddHeader "cache-control", "private"
Response.AddHeader "pragma", "no-cache"
'based on routine from visualbuilder
Function checkMail(sCheckEmail)
Dim isValidMail, location
checkMail = True
isValidMail = Trim(sCheckEmail)
location = InStr(1, isValidMail, "@")
If Not (location > 1 And (InStrRev(isValidMail, ".") > location + 1)) Then
checkMail = False
ElseIf InStr(location + 1, isValidMail, "@") > location Then
checkMail = False
ElseIf Mid(isValidMail, location + 1, 1) = "." Then
checkMail = False
ElseIf InStr(1, Right(isValidMail, 2), ".") > 0 Then
checkMail = False
End If
End Function
'declare our constants
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdTable = &H0002
'our variables
Dim strEmail, objRS , objConn
'get email address from form
strEmail = Request.Form("email")
strEmail = lcase(strEmail)
dim strList
strList = ucase(request.form("list"))
if strList="" then strList="NEWSLETTER"
'check email
validemail = checkMail(strEmail)
If validemail = False Then
'if invalid stay on this page
Response.Redirect ("http://www.glenlaurel.com/news/newsletter.asp")
Else
'create the connection object and open it
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DBQ=" & Server.MapPath("http://www.glenlaurel.com/news/newsletter.mdb")& ";Driver={Microsoft Access Driver (*.mdb)}"
'create recordset object and open it
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open "email" ,objConn ,adopenStatic, adLockOptimistic, adCmdTable
'add new entry
objRS.AddNew
'response.write "huh?"
objRS("email") = strEmail
objRS("list")=strList
'update recordset
objRS.Update
'close everything
objRS.Close
'delete object variables
Set objRS = Nothing
objRS = "DELETE * FROM NoEmail WHERE email = '" +strEmail + "'"
objConn.execute objRS
objConn.Close
Set objConn = Nothing
End If
Response.Redirect ("http://www.glenlaurel.com/home.asp")
%>
-----------------------------------------------------------
If you show me/tell me what I have to change I can probably figure out how to fix the rest of them. If you have access and would like to look at them the links for them are in
http://www.glenlaurel.com/asptosql/
You should be able to download and look at them from there.
PLEASE HELP !