Showing posts with label checking. Show all posts
Showing posts with label checking. Show all posts

Wednesday, March 21, 2012

Front-end input error checking or backend...?

This maybe belongs in the Data-Access Forum, but I'm not sure.

Is it generally a better idea to enforce things like unique constraints in the Database or the Webform? Say for example I want to make sure no duplicate Social Security Numbers are entered. Is it better to have an "If Exists" clause in my query, with a function to deal with it in the application or is it better to just fire the data to SQL Server and let the unique constraint on the dbase column deal with it? I then still have to have some code in my application to deal with the potential exisatance of that number, so is it a case of tomatoe, tomahtoe? If I understand things correctly, SQL server will return an error code if the piece of data does exist, and I will be able to parse the error code and display a message to the user.

Are there performance/coding issues involved? Best practices?In ASP.NET use Validator controls and to disallow duplicates make your table UNIQUE INDEX compatible because SQL Server will not allow the creation of UNIQUE INDEX on Columns that already include duplicate values. Include IGNORE_DUP_KEY in your create INDEX statement. Which means you are using both the application and the database. Hope this helps.

Kind regards,
Gift Peddie

from sql - checking if a file exists in a given share

Hi,
from sql, what is the best way to check if a file exists in a share - given
the file's partial name (for example the first 20 characters) ?
I thought about saving the result set of "xp_cmdShell dir shareName ... "
into a temp table and query the temp table for the filename... but are there
better ways that do not require xp_cmdShell (that needs special permissions
to execute)?
ThanksYou could try using the sp_OA* procedures and the FileSystemObject in VBS.
ML
http://milambda.blogspot.com/|||This sounds interesting. Could you please point me to where I can find
sample code?
Thank you.
"ML" <ML@.discussions.microsoft.com> wrote in message
news:D4DE0DE1-BA83-4810-B385-FC6005DE4B45@.microsoft.com...
> You could try using the sp_OA* procedures and the FileSystemObject in VBS.
>
> ML
> --
> http://milambda.blogspot.com/|||A few samples are available in Books Online, the rest comes down to your
experience with VBS.
This sample demonstrates the use of the sp_OA* procedures:
http://msdn.microsoft.com/library/d...r />
_2ktw.asp
ML
http://milambda.blogspot.com/|||If your on 2005, you could do a UDF such as:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.IO;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static bool FileExists(string path)
{
return File.Exists(path);
}
};
William Stacey [MVP]
"Ramadan" <noOne@.hotmail.com> wrote in message
news:eIcSTaPAGHA.532@.TK2MSFTNGP15.phx.gbl...
> Hi,
> from sql, what is the best way to check if a file exists in a share -
> given
> the file's partial name (for example the first 20 characters) ?
> I thought about saving the result set of "xp_cmdShell dir shareName ...
> "
> into a temp table and query the temp table for the filename... but are
> there
> better ways that do not require xp_cmdShell (that needs special
> permissions
> to execute)?
> Thanks
>|||You can check this via the undocumented procedure (but be aware that
this is undocumented, not supported and could be deppricated in further
versions):
http://www.sql-server-performance.c..._procedures.asp
xp_fileexist
You can use this extended stored procedure to determine whether a
particular file exists on the disk or not. The syntax for this xp is:
EXECUTE xp_fileexist filename [, file_exists INT OUTPUT]
For example, to check whether the file boot.ini exists on disk c: or
not, run:
EXEC master..xp_fileexist 'c:\boot.ini'
HTH, jens Suessmeyer.sql