Replacing all "http" links within InstantForum



The following TSQL script can be executed against your InstantForum database to replace all "http" links with "https" links within all your existing InstantForum posts. This can be helpful if your upgrading your web site to https and wish to ensure all images and links embedded within InstantForum posts use https.

TSQL Find & Replace Script

You will need to execute the below TSQL script against your InstantForum database to replace all references to http with https within your existing InstantForum posts...

DECLARE @find nvarchar(2550)
SET @find = 'http://';


DECLARE @replace nvarchar(2550)
SET @replace = 'https://';


DECLARE @postId int
DECLARE @message nvarchar(max)


DECLARE MSGCURSOR CURSOR FOR 
SELECT PostID, [Message]
FROM InstantForum_Messages

OPEN MSGCURSOR


FETCH NEXT FROM MSGCURSOR
INTO @postId, @message

WHILE @@FETCH_STATUS = 0
BEGIN


DECLARE @index int
SET @index = CHARINDEX(@find, @message);
IF (@index > 0)
BEGIN


SET @message = REPLACE(
@message, 
@find, 
@replace)


UPDATE InstantForum_Messages SET
[Message] = @message 
WHERE PostID = @postId


PRINT CAST(@postId AS nvarchar(255))


END

FETCH NEXT FROM MSGCURSOR
INTO @postId, @message

END
-- tidy cursor
CLOSE MSGCURSOR
DEALLOCATE MSGCURSOR


GO

Updating All User Photos

You should also run the script below to update any user profile photos from http to https...

DECLARE @find nvarchar(2550)
SET @find = 'http://';


DECLARE @replace nvarchar(2550)
SET @replace = 'https://';


DECLARE @userId int
DECLARE @photo nvarchar(max)


DECLARE MSGCURSOR CURSOR FOR 
SELECT UserID, PhotoImage
FROM InstantASP_Users

OPEN MSGCURSOR


FETCH NEXT FROM MSGCURSOR
INTO @userId, @photo

WHILE @@FETCH_STATUS = 0
BEGIN


DECLARE @index int
SET @index = CHARINDEX(@find, @photo);
IF (@index > 0)
BEGIN


SET @photo = REPLACE(
@photo, 
@find, 
@replace)


UPDATE InstantASP_Users SET
PhotoImage = @photo 
WHERE UserID = @userId


PRINT CAST(@userId AS nvarchar(255))


END

FETCH NEXT FROM MSGCURSOR
INTO @userId, @photo

END
-- tidy cursor
CLOSE MSGCURSOR
DEALLOCATE MSGCURSOR


GO

Once you've executed the above SQL code against your InstantForum database you should notice all links within posts now use "https" instead of "http". We hope this helps you make the transition to https.