Opening New Browser Windows Part 1

June 11th, 2009 Russell No comments

I currently have to open a new window in a web application. Here are my requirements:

  1. Must be browser compatible for IE6/7/8, Firefox (all), Opera (all), Chrome and Safari
  2. Must pass parameters to the new page (without using URL parameters)
  3. Must return a value to the old page
  4. Must know whether a window has already be opened, so only 1 is open at a time

According to this site, the target attribute for the anchor tag is being phased out. Therefore it is a better idea to use DOM in javascript to open the window. We need this anyway to meet the requirements for holding on to the new window reference.

I tried the first code example from this site, however it did not work in IE 7. I think a majority of this code is the correct way to go, so I need to work out why it failed in IE 7. I also noticed the resizable config setting had no effect in any of the browsers. That is fine, as this does not break any of the requirements.

I came across an interesting paragraph on the MSDN site, that mentions IE 7 in Windows Vista has access restrictions across process boundaries. It also mentions that when a new window is opened, it creates a new process. This may be an issue as it will make our requirements more difficult to meet.

The issue with IE 7 was related to the title text. I passed in a parameter like so:


function openWindow(url, title)
{
var win = window.open(url, ‘App - ‘ + title, config=”…”);
}

When I simply used:

var win = window.open(url, ‘App’, config=”…”);

Internet Explorer worked fine.

The resizable config setting appears to only work in Internet Explorer. I want consistent behaviour so I will not use this setting. The default value is resizable=no, so I have to explicitly say yes, I do want the window to be resizable. I am trying to make navigation easier for my users, not restrictive.

An object is returned after the window has been opened. This is the object I intend to use to pass the parameters to, be notified when the window has closed and retrieve the returned value. Here is my code so far:

Javascript

function openWindow(url)
{
var win = window.open (url, 'CHCR', config='height=300, \
width=520, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, \
location=no, directories=no, status=no');

}

HTML
<div onclick=”openWindow(’../SuburbLookup.htm’);”>..</div>
This will open my window and meets requirement 1.

Stay tuned for further progress on my window.

SQL Server Create Login Script

June 10th, 2009 Russell No comments

The following code creates a login for a user and assigns it datareader and datawriter access to the database under which this script is run.

Note: This does NOT create permissions to execute stored procedures. To do this, you need to either give the user ‘dbo’ role, or use GRANT EXECUTE statements for each stored procedure.

--Add New User Permissions for X.
IF NOT EXISTS (SELECT * FROM master.dbo.syslogins WHERE name = N'XAppUser')
BEGIN
EXEC master.dbo.sp_addlogin @loginame = N'XAppUser', @passwd = N'pwd#', @deflanguage = N'us_english'
END
GO
IF NOT EXISTS (SELECT * FROM dbo.sysusers WHERE name = N'XAppUser')
EXEC dbo.sp_grantdbaccess @loginame = N'XAppUser', @name_in_db = N'XAppUser'
GO
EXEC sp_addrolemember N'db_datareader', N'XAppUser'
GO
EXEC sp_addrolemember N'db_datawriter', N'XAppUser'
GO

SQL Server Stored Procedure Grants

June 10th, 2009 Russell No comments

We are at the final stages of development and preparing the database scripts to be built. We test on a staging server and realise the user we created doesn’t have permissions to use the stored procedures we created! Ahh!

This means we forgot to grant our stored procedures execute permissions for our user. Normally we put this at the bottom of our stored procedure script:

GO
GRANT EXECUTE ON [dbo].[spAddressInsert] TO [OurUser]
GO

We are at the end of development and it will take way too long to add this to each script. What to do!

We can query the database to find all stored procedures in the database, and create a list of grant commands. Note they must be separated with GO’s. Here is some sample code to do this:

SELECT 'GRANT EXECUTE ON [dbo].['+[name]+’] TO [OurUser]
GO’

FROM sys.objects WHERE TYPE=’P’

Run this in a SQL management program (SQL management studio or Toad) and output the result to text. You will have a list of grant commands for all of your stored procedures!

F# Useful Sites P1

June 9th, 2009 Russell No comments
Categories: Microsoft .Net, Uncategorized Tags: ,

F# (FSharp)

June 9th, 2009 Russell No comments

F Sharp is a new language available for the .Net framework.
It is a functional language, so requires a different mindset from C#. It is still in beta so it is a good idea to keep it out of production code for now.

I started investigating F# because I saw the potential for using to leverage code written by C#. F# can easily call a function, passing in a list of parameters. (Using the List.map function) Therefore, I can call a method many times with the minimal amount of code.

I am using F# at the moment for initial unit testing during development. I can the WCF service independently of the web (ASP .net) site. Integration testing is done afterwards, however this provides a simple way to test the data/business layers as I go.