Nik's Technology Blog

Travels through programming, networks, and computers

Fix Orphaned Users in SQL Server after Restoring a Database to another Server

Orphaned users can be created in a database when it is restored to a different server. This happens because not only does the database keep a record of users (sysusers), but so does SQL Server (sysxlogins) in the Master database.

So when you do a restore to a different server the SQL logins in the Master database don't link to the users in the restored database, this is the case even if a login exists with the same name. This is the case because each login has an associated SID (Security Identifier).

Common symptoms of this problem are:

  • Applications may experience 'login failed' error messages and fail to log into the database.
  • Users won't show up in Enterprise Manager, but when you try to add these users, you will get error messages saying 'User or role already exists in the current database'

Solution:

Used stored procedure - sp_change_users_login. You will need to create the account you wish to change users to before running this stored procedure.

--Change the user account to link with the 'NewHarry' login.

USE Books

go

EXEC sp_change_users_login 'Update_One', 'Harry', 'NewHarry'

This will change the user Harry in the restored database to link with NewHarry instead.

How to troubleshoot orphan users in SQL Server databases?

BT Trials 'Midband' a step away from Broadband?

BT is testing what it has coined 'Midband'. It's primarily for homes in the UK that cannot at present receive BT Broadband. BT broadband currently covers 77% of BT's network, other areas are currently being upgraded where there is demand.

Midband will feature an always-on connection, and run at 128kbps.

Experts think they will probably use ISDN for this service, using ISDN's 16kbps D-Channel for the always-on connection, which can be used for receiving emails, and the 2 B-Channels (64kbps each) for simultaneous data and voice.

If this is the case then dialling up will be necessary, although ISDN dial-up is significantly faster than a traditional modem.

Adding Page Breaks to HTML Documents

Using the CSS style attribute "page-break-before" you can place page breaks within your document, enabling the web designer to control how the document prints.

For example you could add them to <hr> tags as an in-line style or as part of your external CSS document.

SYNTAX

INLINE STYLE

<hr style="page-break-before: always">

OR IN CSS

hr {page-break-before: always;}

Compatible with Internet Explorer 4 upwards and Netscape 6/Mozilla.

W3 Schools reference to "page-break-before"

Generic web form emailer using FOR EACH and CDONTs

The ASP code below will loop through all the requested form fields submitted to it and send a CDO email from your server to your email account with the values of all those fields.

PROCESS PAGE

<%

Dim cdoMail, Recipient, Subject, Redirect, Sender, item, MailText

Recipient = "my_account@nobody.com"

Subject = "Enquiry from website"

Redirect = "index.html"

Sender = "server@nobody.com"

  MailText = "Email received from my website"

for each item in request.form

  MailText = MailText & item & ": " & request.form(item) & vbcrlf

next

Set cdoMail = Server.CreateObject("CDONTS.NewMail")

  cdoMail.From = Sender

  cdoMail.To = Recipient

  cdoMail.Subject = Subject

  cdoMail.Body = MailText

  cdoMail.Send

Set cdoMail = Nothing

Response.Redirect Redirect

%>

For more information about the FOR EACH vbscript statement please see my previous post below.

Simple ASP Form Collection with FOR EACH

The code below shows how to grab form submitted data from a page by looping through all submitted form items using the FOR EACH vbscript code.

Note: The submit button does NOT have a NAME attribute, this is so it doesn't appear within the fields on the process page.

The code can be altered to loop through query string data aswell. Simply replace "for each item in request.form" with "for each item in request.querystring".

FORM PAGE

<html><head><title>Lazy Man's Form Collection using FOR EACH in ASP</title></head><body>

<form action="form_collection.asp" method="post"> <input type="text" name="Name">

<input type="text" name="Address">

<input type="text" name="Country">

<input type="text" name="Age">

<input type="submit" value="submit">

</form>

</body></html>

PROCESS PAGE

<html><head><title>Form Collection</title></head><body>

<%

for each item in request.form

response.write "<b>" & item & ":</b> " & request.form(item) & "<br>"

next

%>

</body></html>

BDO Bi-directional Override HTML Tag

The <bdo> HTML tag is used to override the default direction of text. This can be handy when a web page contains paragraphs of other languages such as Chinese.

Attributes for this tag include:

dir - Specifies the direction [ltr or rtl]

lang - Specifies Language Code (RFC 1766)

This is the only tag that will reverse the direction of text so far and is only supported by Internet Explorer 5 upwards.

RFC 1766 Language Codes

ACRONYMS and HTML

There are two different ways to define the meaning of an acronym within an HTML document, the ACRONYM tag and the ABBR tag. In practise they are very similar, although their compatibility varies with browsers.

Examples

<acronym title="Hypertext Markup Language">HTML</acronym>

<abbr title="Extensible Markup Language">XML</abbr>

<ABBR> is only compatible with Netscape 6 upwards (Mozilla) whereas <ACRONYM> is supported by Internet Explorer 4 upwards and Netscape 6 upwards. It's probably a better choice to opt with <ACRONYM> in light of this.

Website Spam Avoidance - Javascript Code

Use the following JavaScript if you want to display an email address on your website, but you don't want to receive spam mail. It will avoid getting picked up by Spammer's email collecting scripts.

<script language="JavaScript" type="text/javascript">

<!--

var LinkText = "click here";

var e1 = "mail";

var e2 = "to:";

var EmailPart1 = "yourname";

var EmailPart2 = "yourdomain";

var EmailPart3 = ".com";

document.write("<a h" + "ref=" + e1 + e2 + EmailPart1 + "@" + EmailPart2 + EmailPart3 + ">" + LinkText + "</a>")

//-->

</script>

Web Design Considerations

  • Are the pages printable on A4/US letter paper?
  • Does the site work on all browsers? (Cross-Browser functionality) (Netscape and Opera as well as Internet Explorer etc)
  • Does the site work on Apple Macs, Unix and PCs etc? (Cross-Platform functionality)
  • Can you see the whole of the site in common screen resolutions (800x600, 1024x768) without scrolling?
  • Have you stuck to common fonts such as Arial, Lucida, Verdana and Georgia? (Some fonts won't be installed on visitors' machines)
  • Can the text on the screen be read comfortably? Try to avoid clashing background images and colours as it will be difficult for the visually impaired to read.
  • Is the navigation intuitive? If you are using images as navigation do they have ALT tags? Try adding text navigation at the bottom of the page; this will help if the visitors' connection is slow as they will still be able to navigate the site.
  • Are the images optimised and quick to download? Have you used GIF and JPEG formats for the right type of images?
  • Have you used web safe colours? (Some screens can only display 256 colours) Web safe colours

HTML Forms - Usability

Making HTML forms easier for the user is no easy task.

Make good use of Radio buttons, Check boxes and drop-down menus within the form instead of text boxes where possible to keep the users typing down to a minimum.

Use the "Tabindex" HTML form attribute to set the tabbing order if your HTML forms are large and complex.

Make clear which elements of a form are compulsory with and * or similar, stating what the asterix is for at the top. If you think any of the fields might be filled in wrongly, then think about adding help pages (pop-ups) for the form.

If your form is asking for personal data, then link to your site's privacy policy on the page. Information such as Credit Card details should only be submitted over a secure SSL (Secure Sockets Layer) connection, you will need to set this up if you don't already have one.

If you already have data on the user then pre-populate the fields and ask for confirmation where necessary, this will save the user re-typing them.

Finally you will be able to judge your forms usability by how many badly filled forms you receive.

HTML tabindex