显示标签为“write”的博文。显示所有博文
显示标签为“write”的博文。显示所有博文

2012年3月22日星期四

Flat File Processing - Cannot get Error Output to Write

I cannot seem to get my flat file to write columns in error when inserting into a SQL table. I have tried a few examples from MS and did not get anything written to my flat file output. I have set the Source Error Output on this flat file and it uses a script task to created the error description and then write it to a Flat File Destination.

I am new to SSIS and have not had any formal training on it. However, I am very familiar with VS.Net/c# and SQL 2000 DTS - I need to get this working ASAP as there are 45 total flat files that need to be processed. Once I have this solved for one, the rest will follow suit.

If more details would help, I can provide them.

Kind Regards,

Ron

Yep, please provide more details. Any error messages? What doesn't work, exactly?|||I'm confused about what you're trying to do. Can you try the description again?
|||

Well, I have my flat file source and my SQL server destination. One flat file represents a table and the SQL destination represents one table. The columns are all mapped one-to-one exactly. I had to modify the flat file source data types to get rid of the data type errors. When I run the package, this task fails because of a datatype error. One of the datetime fields is not valid. The flat file that I am having troubles with has 145 columns and about 25000 rows. I have 45 total flat files I need to process. The one that I am having troubles with and would like to log the errors for, is the longest in terms of columns.

Currently, I have the Error Output going to a Script Component that has an output column for Error Description. Under this I have the Flat File Destination that I would like to write the error to. I have tested with a smaller flat file and I manually corrupted the file so it would fail, but this still did not write any error output.

I honestly did not think that what I was doing with SSIS was going to be this challenging, but I was wrong. The high-level overview of what I am ultimately trying to do is process 45 flat files into a SQL DB with 45 tables. The field names in both source and destination are the same. We would eventually like to add some process logging and other check points, but we have to get this proof of concept going first.

Hope this helps a bit more.

|||

ronemac wrote:

Well, I have my flat file source and my SQL server destination. One flat file represents a table and the SQL destination represents one table. The columns are all mapped one-to-one exactly. I had to modify the flat file source data types to get rid of the data type errors. When I run the package, this task fails because of a datatype error. One of the datetime fields is not valid. The flat file that I am having troubles with has 145 columns and about 25000 rows. I have 45 total flat files I need to process. The one that I am having troubles with and would like to log the errors for, is the longest in terms of columns.

Currently, I have the Error Output going to a Script Component that has an output column for Error Description. Under this I have the Flat File Destination that I would like to write the error to. I have tested with a smaller flat file and I manually corrupted the file so it would fail, but this still did not write any error output.

I honestly did not think that what I was doing with SSIS was going to be this challenging, but I was wrong. The high-level overview of what I am ultimately trying to do is process 45 flat files into a SQL DB with 45 tables. The field names in both source and destination are the same. We would eventually like to add some process logging and other check points, but we have to get this proof of concept going first.

Hope this helps a bit more.

In the error output area of the Source Adapter, have you made sure that Redirect Row is set on all the appropriate choices (Error and Truncation for each column)?

|||Yes sir.|||So what I have is this:
Flat File Source --> SQL Server Destination
After this fails (the SQL Server Destination is Red while the Flat File Source is green) I look at the Execution Results and I see that the SQL Server Destination had a conversion issue - (Error converting data type DBTYPE_DBTIMESTAMP to datetime)
Unfortunately, there are roughly 20 datetime columns in this table - 145 total columns - so I have no idea which column in which row is failing.
I would like to capture each row (row ID) and column that is failing so I can log it and reject the file. I have tried adding a script task and using the Error Output from the Flat File Source, but I don't even know if this is the correct place. I am sure the file structure looks just fine to SSIS, it's when SQL tries to insert the data that the DT conversion fails.
Suggestions?|||

Redirect errors from the SQL Server destination.

|||

That is what I WANT to do, but did not think that was possible - there is no Red arrow for error output on the SQL Destincation Data Flow Component... DId I mention that I was new to SSIS? Sorry.

|||

Ron,

Some stuff here that may help:

Get error descriptions

(http://blogs.conchango.com/jamiethomson/archive/2005/08/08/SSIS-Nugget_3A00_-Get-error-descriptions.aspx)

Enhanced Error Transform (adds the name of the column in which the error occurred):

(http://sqlblogcasts.com/blogs/simons/archive/2005/09/21/637.aspx)

-Jamie

|||

Yep, sorry, try using an OLE DB destination instead.

SQL Server destinations are an "in-memory" hook to SQL Server. It is a strongly typed destination and requires that all fields are the correct data type and constraints have been met, etc...

|||

Cool.. I will give it a rip. Thanks again.

|||Right on! And thank you for your help!

Flat File Processing - Cannot get Error Output to Write

I cannot seem to get my flat file to write columns in error when inserting into a SQL table. I have tried a few examples from MS and did not get anything written to my flat file output. I have set the Source Error Output on this flat file and it uses a script task to created the error description and then write it to a Flat File Destination.

I am new to SSIS and have not had any formal training on it. However, I am very familiar with VS.Net/c# and SQL 2000 DTS - I need to get this working ASAP as there are 45 total flat files that need to be processed. Once I have this solved for one, the rest will follow suit.

If more details would help, I can provide them.

Kind Regards,

Ron

Yep, please provide more details. Any error messages? What doesn't work, exactly?|||I'm confused about what you're trying to do. Can you try the description again?
|||

Well, I have my flat file source and my SQL server destination. One flat file represents a table and the SQL destination represents one table. The columns are all mapped one-to-one exactly. I had to modify the flat file source data types to get rid of the data type errors. When I run the package, this task fails because of a datatype error. One of the datetime fields is not valid. The flat file that I am having troubles with has 145 columns and about 25000 rows. I have 45 total flat files I need to process. The one that I am having troubles with and would like to log the errors for, is the longest in terms of columns.

Currently, I have the Error Output going to a Script Component that has an output column for Error Description. Under this I have the Flat File Destination that I would like to write the error to. I have tested with a smaller flat file and I manually corrupted the file so it would fail, but this still did not write any error output.

I honestly did not think that what I was doing with SSIS was going to be this challenging, but I was wrong. The high-level overview of what I am ultimately trying to do is process 45 flat files into a SQL DB with 45 tables. The field names in both source and destination are the same. We would eventually like to add some process logging and other check points, but we have to get this proof of concept going first.

Hope this helps a bit more.

|||

ronemac wrote:

Well, I have my flat file source and my SQL server destination. One flat file represents a table and the SQL destination represents one table. The columns are all mapped one-to-one exactly. I had to modify the flat file source data types to get rid of the data type errors. When I run the package, this task fails because of a datatype error. One of the datetime fields is not valid. The flat file that I am having troubles with has 145 columns and about 25000 rows. I have 45 total flat files I need to process. The one that I am having troubles with and would like to log the errors for, is the longest in terms of columns.

Currently, I have the Error Output going to a Script Component that has an output column for Error Description. Under this I have the Flat File Destination that I would like to write the error to. I have tested with a smaller flat file and I manually corrupted the file so it would fail, but this still did not write any error output.

I honestly did not think that what I was doing with SSIS was going to be this challenging, but I was wrong. The high-level overview of what I am ultimately trying to do is process 45 flat files into a SQL DB with 45 tables. The field names in both source and destination are the same. We would eventually like to add some process logging and other check points, but we have to get this proof of concept going first.

Hope this helps a bit more.

In the error output area of the Source Adapter, have you made sure that Redirect Row is set on all the appropriate choices (Error and Truncation for each column)?

|||Yes sir.|||So what I have is this:
Flat File Source --> SQL Server Destination
After this fails (the SQL Server Destination is Red while the Flat File Source is green) I look at the Execution Results and I see that the SQL Server Destination had a conversion issue - (Error converting data type DBTYPE_DBTIMESTAMP to datetime)
Unfortunately, there are roughly 20 datetime columns in this table - 145 total columns - so I have no idea which column in which row is failing.
I would like to capture each row (row ID) and column that is failing so I can log it and reject the file. I have tried adding a script task and using the Error Output from the Flat File Source, but I don't even know if this is the correct place. I am sure the file structure looks just fine to SSIS, it's when SQL tries to insert the data that the DT conversion fails.
Suggestions?|||

Redirect errors from the SQL Server destination.

|||

That is what I WANT to do, but did not think that was possible - there is no Red arrow for error output on the SQL Destincation Data Flow Component... DId I mention that I was new to SSIS? Sorry.

|||

Ron,

Some stuff here that may help:

Get error descriptions

(http://blogs.conchango.com/jamiethomson/archive/2005/08/08/SSIS-Nugget_3A00_-Get-error-descriptions.aspx)

Enhanced Error Transform (adds the name of the column in which the error occurred):

(http://sqlblogcasts.com/blogs/simons/archive/2005/09/21/637.aspx)

-Jamie

|||

Yep, sorry, try using an OLE DB destination instead.

SQL Server destinations are an "in-memory" hook to SQL Server. It is a strongly typed destination and requires that all fields are the correct data type and constraints have been met, etc...

|||

Cool.. I will give it a rip. Thanks again.

|||Right on! And thank you for your help!sql

Flat File Destination - File name

Hello,

I'm trying to send a file with FTP.

In the Flat File connection manager I have to write the name of the file.

Is there any way of deciding at runtime what the name of the file should be?

Thank you.

Yes. Use expressions.

http://blogs.conchango.com/jamiethomson/archive/tags/Expressions/default.aspx

-Jamie

|||

Hi Chaps

I am trying to achieve a similar thing with the FTP Task
ie incorporate the date into the filename when sending the file.

I have set IsRemotePathVariable=True


I have created an expression for the RemotePath:
"/FName"+ (DT_WSTR,4)DatePart("yyyy", GetDate())
+ (DT_WSTR,2)DatePart("mm", GetDate())
+ (DT_WSTR,2)DatePart("dd", GetDate())+".txt"

However, an error is produced:
"Error at FTP Task: Failed to lock variable"/FName2007611.txt"

Should I be linking the expression to a variable ?
and if so how

Any guidance would be very much appreciated.

Regards

JohnJames
|||

Hi,

Just so I understand this correctly, do you use a hard coded file name in the Data Flow Flat File Destination (f.ex. outputfile.txt) and then afterwards in the Control Flow you change the file name (f.ex. outputfile_11_06_2007.txt) by using these expressions?

Thank you.

|||Yes

In the Dataflow I am using a hard-coded filename,
to extract data from SQL Server to a flatfile.
In the Control Flow is the FTP Task where I am trying to add
the Date to filename using an expression.

Regards

JohnJames
|||Why don't you create a variable who's value is an expression. You then use the variable in the data flow and the FTP task. That way you are always guaranteed that the file name is correct.
Saves you from having to rename a file as well..|||Thanks Crispin

I'll give a go and let you know

Regards

JohnJames|||

Hi,

I'm trying to decide the filename of my Flat File Destination at run time by using an expression variable.

I created an expression variable:

Name: FileName_Expression Value: C:\test.txt

However, in the Data Flow in Flat File connection manager, I can't seem to put my variable name inside the "File Name" editbox and I have no idea where to put my expression variable.

Any ideas?

Thank you so much!!!

|||

Mr. Hat,

Use the connectionstring property of the flat file connection manager.

ex. ConnectionString = @.[User::myPath] + "\\ERROR_" + @.[User::FileName_Expression]

(Where myPath is something similar to C:\temp)

NOTE: new questions like this should probably get a new thread as many people will just look past the threads which appear to have already been answered.

Hope this helps.

EWisdahl

|||Wow, it worked! Thanks a lot!! Big Smile|||

Hi

when i'm trying to set the file name runtime for excel destination by setting expression

ConnectionString : @.[User::ExcelFullFileName]

but getting below error

Error at Data Flow Task [Excel Destination [7689]]: The AcquireConnection method call to the connection manager "Excel Connection Manager" failed with error code 0xC0202009.

please can you advice regarding this?|||I believe (but I may be wrong) that the Excel file needs to exist to be referenced by the Connection Manager.sql

2012年3月9日星期五

Fix my SQL "WHERE" Statement!

I'm working on an ASP Web application, and am having syntax issues in
a WHERE statement I'm trying to write that uses the CInt Function on a
field.

Basically, I want to select records using criteria of Race, Gender and
Crime Code. But the Crime Code field in the table is text, and I
cannot change it. I want to use a range of crime codes, so need to
convert it to an integer on-the-fly. Here's what I have in my code so
far:

varSQL = "SELECT PrisonRelease.*, Defendant.*, Arrest.* "

varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
ARREST on DEFENDANT.Defendant_ID = ARREST.Defendant_ID) ON
PrisonRelease.PID = Defendant.PID_Code "

varSQL = varSQL & "WHERE DEFENDANT.Race_Type_Code_L in (" &
varRaceList & ")AND DEFENDANT.Gender In (" & varGenderList & ") "

varSQL = varSQL & "AND
(IIf(IsNull(Defendant.[CRIME_CLASSIFICATION_CODE]) Or
Defendant.[CRIME_CLASSIFICATION_CODE]="" Or
(Defendant.[CRIME_CLASSIFICATION_CODE]) Not Like "[0-9][0-9][0-9]" And
Defendant.[CRIME_CLASSIFICATION_CODE] Not Like
"[0-9][0-9][0-9][0-9]"),9999,CInt(Defendant.[CRIME_CLASSIFICATION_CODE])
Between 1800 And 1899) "

When I try to execute this code on my Web page, I get an error. But it
works fine in Access, with some minor syntax changes. What am I
missing?!

Thanks,
Rachel WeedenRachelWeeden@.hotmail.com (Rachel Weeden) wrote in message news:<f5066a28.0408230526.3f881906@.posting.google.com>...
> I'm working on an ASP Web application, and am having syntax issues in
> a WHERE statement I'm trying to write that uses the CInt Function on a
> field.
> Basically, I want to select records using criteria of Race, Gender and
> Crime Code. But the Crime Code field in the table is text, and I
> cannot change it. I want to use a range of crime codes, so need to
> convert it to an integer on-the-fly. Here's what I have in my code so
> far:
> varSQL = "SELECT PrisonRelease.*, Defendant.*, Arrest.* "
> varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
> ARREST on DEFENDANT.Defendant_ID = ARREST.Defendant_ID) ON
> PrisonRelease.PID = Defendant.PID_Code "
> varSQL = varSQL & "WHERE DEFENDANT.Race_Type_Code_L in (" &
> varRaceList & ")AND DEFENDANT.Gender In (" & varGenderList & ") "
> varSQL = varSQL & "AND
> (IIf(IsNull(Defendant.[CRIME_CLASSIFICATION_CODE]) Or
> Defendant.[CRIME_CLASSIFICATION_CODE]="" Or
> (Defendant.[CRIME_CLASSIFICATION_CODE]) Not Like "[0-9][0-9][0-9]" And
> Defendant.[CRIME_CLASSIFICATION_CODE] Not Like
> "[0-9][0-9][0-9][0-9]"),9999,CInt(Defendant.[CRIME_CLASSIFICATION_CODE])
> Between 1800 And 1899) "
> When I try to execute this code on my Web page, I get an error. But it
> works fine in Access, with some minor syntax changes. What am I
> missing?!
> Thanks,
> Rachel Weeden

I think it is because you are using [] brackets which is a access
syntax and not asp.|||RachelWeeden@.hotmail.com (Rachel Weeden) wrote in message news:<f5066a28.0408230526.3f881906@.posting.google.com>...
> I'm working on an ASP Web application, and am having syntax issues in
> a WHERE statement I'm trying to write that uses the CInt Function on a
> field.
> Basically, I want to select records using criteria of Race, Gender and
> Crime Code. But the Crime Code field in the table is text, and I
> cannot change it. I want to use a range of crime codes, so need to
> convert it to an integer on-the-fly. Here's what I have in my code so
> far:
> varSQL = "SELECT PrisonRelease.*, Defendant.*, Arrest.* "
> varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
> ARREST on DEFENDANT.Defendant_ID = ARREST.Defendant_ID) ON
> PrisonRelease.PID = Defendant.PID_Code "
> varSQL = varSQL & "WHERE DEFENDANT.Race_Type_Code_L in (" &
> varRaceList & ")AND DEFENDANT.Gender In (" & varGenderList & ") "
> varSQL = varSQL & "AND
> (IIf(IsNull(Defendant.[CRIME_CLASSIFICATION_CODE]) Or
> Defendant.[CRIME_CLASSIFICATION_CODE]="" Or
> (Defendant.[CRIME_CLASSIFICATION_CODE]) Not Like "[0-9][0-9][0-9]" And
> Defendant.[CRIME_CLASSIFICATION_CODE] Not Like
> "[0-9][0-9][0-9][0-9]"),9999,CInt(Defendant.[CRIME_CLASSIFICATION_CODE])
> Between 1800 And 1899) "
> When I try to execute this code on my Web page, I get an error. But it
> works fine in Access, with some minor syntax changes. What am I
> missing?!
> Thanks,
> Rachel Weeden

I think it is because you are using [] brackets which is a access
syntax and not asp.|||CInt is not supported in SQL-Server. You can use CAST or CONVERT
instead.

IIf it not supported in SQL-Server. You can use the CASE expression,
although it works slightly different, so you will need to rewrite that
part.

Have a look at SQL-Server Books Online for more information and
examples.

Hope this helps,
Gert-Jan

Rachel Weeden wrote:
> I'm working on an ASP Web application, and am having syntax issues in
> a WHERE statement I'm trying to write that uses the CInt Function on a
> field.
> Basically, I want to select records using criteria of Race, Gender and
> Crime Code. But the Crime Code field in the table is text, and I
> cannot change it. I want to use a range of crime codes, so need to
> convert it to an integer on-the-fly. Here's what I have in my code so
> far:
> varSQL = "SELECT PrisonRelease.*, Defendant.*, Arrest.* "
> varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
> ARREST on DEFENDANT.Defendant_ID = ARREST.Defendant_ID) ON
> PrisonRelease.PID = Defendant.PID_Code "
> varSQL = varSQL & "WHERE DEFENDANT.Race_Type_Code_L in (" &
> varRaceList & ")AND DEFENDANT.Gender In (" & varGenderList & ") "
> varSQL = varSQL & "AND
> (IIf(IsNull(Defendant.[CRIME_CLASSIFICATION_CODE]) Or
> Defendant.[CRIME_CLASSIFICATION_CODE]="" Or
> (Defendant.[CRIME_CLASSIFICATION_CODE]) Not Like "[0-9][0-9][0-9]" And
> Defendant.[CRIME_CLASSIFICATION_CODE] Not Like
> "[0-9][0-9][0-9][0-9]"),9999,CInt(Defendant.[CRIME_CLASSIFICATION_CODE])
> Between 1800 And 1899) "
> When I try to execute this code on my Web page, I get an error. But it
> works fine in Access, with some minor syntax changes. What am I
> missing?!
> Thanks,
> Rachel Weeden

--
(Please reply only to the newsgroup)|||"Rachel Weeden" wrote:

> I'm working on an ASP Web application, and am having syntax issues in
> a WHERE statement I'm trying to write that uses the CInt Function on a
> field.
> Basically, I want to select records using criteria of Race, Gender and
> Crime Code. But the Crime Code field in the table is text, and I
> cannot change it. I want to use a range of crime codes, so need to
> convert it to an integer on-the-fly. Here's what I have in my code so
> far:
> varSQL = "SELECT PrisonRelease.*, Defendant.*, Arrest.* "
> varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
> ARREST on DEFENDANT.Defendant_ID = ARREST.Defendant_ID) ON
> PrisonRelease.PID = Defendant.PID_Code "
> varSQL = varSQL & "WHERE DEFENDANT.Race_Type_Code_L in (" &
> varRaceList & ")AND DEFENDANT.Gender In (" & varGenderList & ") "
> varSQL = varSQL & "AND
> (IIf(IsNull(Defendant.[CRIME_CLASSIFICATION_CODE]) Or
> Defendant.[CRIME_CLASSIFICATION_CODE]="" Or
> (Defendant.[CRIME_CLASSIFICATION_CODE]) Not Like "[0-9][0-9][0-9]" And
> Defendant.[CRIME_CLASSIFICATION_CODE] Not Like
> "[0-9][0-9][0-9][0-9]"),9999,CInt(Defendant.[CRIME_CLASSIFICATION_CODE])
> Between 1800 And 1899) "
> When I try to execute this code on my Web page, I get an error. But it
> works fine in Access, with some minor syntax changes. What am I
> missing?!
> Thanks,
> Rachel Weeden

Rachel,

[Note: I typed some of the T-SQL code in my newsreader, so formatting and
syntax may be a little goofy, but it should get you started in the right
direction.]

The square brackets are OK in T-SQL. The problem you're having is that your
WHERE clause is using VBA functions. While this is a cool feature in the
JET database engine, you can't use it in T-SQL (or any other DB environment
that I'm aware of). As others have mentioned:

- Use CAST or CONVERT instead of CInt (or any of the VB casting functions
e.g. CStr, CDbl, etc)

- Use CASE instead of IIf

Also,

- In VB, IsNull is a boolean function that returns true if the single
argument is NULL. In SQL Server T-SQL, ISNULL is a function that takes 2
parameters; if the first argument is NULL it returns the second else it
returns the first. For example:

ISNULL(NULL, 1) returns 1
...and...
ISNULL(2, 1) returns 2

A rough translation of your code would go something like (watch out for word
wrap and funny formatting)...

AND (
CASE
WHEN ISNULL(Defendant.[CRIME_CLASSIFICATION_CODE], '') = ''
THEN 9999

WHEN Defendant.[CRIME_CLASSIFICATION_CODE] Not Like '[0-9][0-9][0-9]' AND
Defendant.[CRIME_CLASSIFICATION_CODE] Not Like '[0-9][0-9][0-9][0-9]'
THEN 9999

ELSE
CASE WHEN CONVERT(int, Defendant.[CRIME_CLASSIFICATION_CODE]) BETWEEN
1800 AND 1899
THEN 1
ELSE 0
END
END
)

However, it appears you want something akin to "WHERE
Defendant.[CRIME_CLASSIFICATION_CODE] isn't an appropriate numeric
representation or it is numeric and is inclusively in the range 1800-1899".
If I'm correct, you could use something like this (tested in Query Analyzer
with SQL Server 2000)...

DECLARE @.tab TABLE (
d varchar(32),
ccc varchar(20)
)

INSERT @.tab VALUES ('Num outside range', '1750')
INSERT @.tab VALUES ('Num in range', '1800')
INSERT @.tab VALUES ('Not a num', 'aaa')
INSERT @.tab VALUES ('NULL', NULL)
INSERT @.tab VALUES ('Empty string', '')

SELECT *
FROM @.tab
WHERE CASE WHEN ISNUMERIC(ccc) = 1
THEN
CASE WHEN CONVERT(int, ccc) BETWEEN 1800 AND 1899
THEN 1
ELSE 0
END
ELSE 1
END = 1

This returns everything in the test table except the 'Num outside range'
row.

Craig|||Thanks for all the input, Craig - I have taken some time to look over
your code, and I understand the basics about replacing some of my VB
functions with T-SQL ones. Problem is, I am very inexperienced with
SQL (this page is my first project, really!), so the details are a
little confusing.

For example, I've never heard of T-SQL before. I assumed I was writing
a SQL statement in a VB script on an ASP page...but that's a new
acronym for me! Also, the code you included looks totally different
than anything else on my page, so I am having trouble figuring out
where it all fits in, etc.

But I will look into this a bit more, and I'm sure your suggestions
about CAST, CONVERT, CASE, etc. will come in handy.

Thanks again,
Rachel

"Craig Kelly" <cnkelly.nospam@.nospam.net> wrote in message news:<v5tWc.504132$Gx4.393231@.bgtnsc04-news.ops.worldnet.att.net>...
> "Rachel Weeden" wrote:
> > I'm working on an ASP Web application, and am having syntax issues in
> > a WHERE statement I'm trying to write that uses the CInt Function on a
> > field.
> > Basically, I want to select records using criteria of Race, Gender and
> > Crime Code. But the Crime Code field in the table is text, and I
> > cannot change it. I want to use a range of crime codes, so need to
> > convert it to an integer on-the-fly. Here's what I have in my code so
> > far:
> > varSQL = "SELECT PrisonRelease.*, Defendant.*, Arrest.* "
> > varSQL = varSQL & "FROM PrisonRelease LEFT JOIN (DEFENDANT LEFT JOIN
> > ARREST on DEFENDANT.Defendant_ID = ARREST.Defendant_ID) ON
> > PrisonRelease.PID = Defendant.PID_Code "
> > varSQL = varSQL & "WHERE DEFENDANT.Race_Type_Code_L in (" &
> > varRaceList & ")AND DEFENDANT.Gender In (" & varGenderList & ") "
> > varSQL = varSQL & "AND
> > (IIf(IsNull(Defendant.[CRIME_CLASSIFICATION_CODE]) Or
> > Defendant.[CRIME_CLASSIFICATION_CODE]="" Or
> > (Defendant.[CRIME_CLASSIFICATION_CODE]) Not Like "[0-9][0-9][0-9]" And
> > Defendant.[CRIME_CLASSIFICATION_CODE] Not Like
> > "[0-9][0-9][0-9][0-9]"),9999,CInt(Defendant.[CRIME_CLASSIFICATION_CODE])
> > Between 1800 And 1899) "
> > When I try to execute this code on my Web page, I get an error. But it
> > works fine in Access, with some minor syntax changes. What am I
> > missing?!
> > Thanks,
> > Rachel Weeden
> Rachel,
> [Note: I typed some of the T-SQL code in my newsreader, so formatting and
> syntax may be a little goofy, but it should get you started in the right
> direction.]
> The square brackets are OK in T-SQL. The problem you're having is that your
> WHERE clause is using VBA functions. While this is a cool feature in the
> JET database engine, you can't use it in T-SQL (or any other DB environment
> that I'm aware of). As others have mentioned:
> - Use CAST or CONVERT instead of CInt (or any of the VB casting functions
> e.g. CStr, CDbl, etc)
> - Use CASE instead of IIf
> Also,
> - In VB, IsNull is a boolean function that returns true if the single
> argument is NULL. In SQL Server T-SQL, ISNULL is a function that takes 2
> parameters; if the first argument is NULL it returns the second else it
> returns the first. For example:
> ISNULL(NULL, 1) returns 1
> ...and...
> ISNULL(2, 1) returns 2
> A rough translation of your code would go something like (watch out for word
> wrap and funny formatting)...
> AND (
> CASE
> WHEN ISNULL(Defendant.[CRIME_CLASSIFICATION_CODE], '') = ''
> THEN 9999
> WHEN Defendant.[CRIME_CLASSIFICATION_CODE] Not Like '[0-9][0-9][0-9]' AND
> Defendant.[CRIME_CLASSIFICATION_CODE] Not Like '[0-9][0-9][0-9][0-9]'
> THEN 9999
> ELSE
> CASE WHEN CONVERT(int, Defendant.[CRIME_CLASSIFICATION_CODE]) BETWEEN
> 1800 AND 1899
> THEN 1
> ELSE 0
> END
> END
> )
> However, it appears you want something akin to "WHERE
> Defendant.[CRIME_CLASSIFICATION_CODE] isn't an appropriate numeric
> representation or it is numeric and is inclusively in the range 1800-1899".
> If I'm correct, you could use something like this (tested in Query Analyzer
> with SQL Server 2000)...
> DECLARE @.tab TABLE (
> d varchar(32),
> ccc varchar(20)
> )
> INSERT @.tab VALUES ('Num outside range', '1750')
> INSERT @.tab VALUES ('Num in range', '1800')
> INSERT @.tab VALUES ('Not a num', 'aaa')
> INSERT @.tab VALUES ('NULL', NULL)
> INSERT @.tab VALUES ('Empty string', '')
> SELECT *
> FROM @.tab
> WHERE CASE WHEN ISNUMERIC(ccc) = 1
> THEN
> CASE WHEN CONVERT(int, ccc) BETWEEN 1800 AND 1899
> THEN 1
> ELSE 0
> END
> ELSE 1
> END = 1
> This returns everything in the test table except the 'Num outside range'
> row.
> Craig

2012年2月26日星期日

First Data Processing Extension Problem

I am trying to write my first data processing extension. The project
is based upon the Event Log example in chapter 13 of Hitchhiker's
Guide to SQL Server 2000 Reporting Services. The assembly has been
copied to the various directories and the various config files have
been modified.
The extension is used in a report project and a shared datasource is
created using the extension. When a report's dataset is created the
Fields window in the IDE is not populated. When the command is run in
the data window of the designer a null pointer error occurs. In the
preview window the error indicates the connection is not valid. This
project is written in C# and the supplied sample is written in VB.NET.
The same error occurs using the VB assemblies.
The "connection not valid" exception is generated from command class'
ExecuteReader method. The connection member is found to be null w/in
the method. In the overloaded c'tor where the connection argument is
assigned to the connection member, the argument is not null and the
member is not null after it has been assigned to. I am baffled as to
what/why/how this occuring. Suggestion?
Equally or more important how does one setup a data processing
extension project for debugging?
thank you
A.G.All issues resolved. Using System.Diagnostics.Debugger.Break I was
able to access the CLR debugger and see what was wrong. First problem
was a typo in a string. Then an indexing error was found and then the
extension 'worked' returning just a single record.
A closer examination of the datareader's Read method revealed a number
of issues involving the iteration of the event log. Changing the
method so it read one record at a time made everything work as
expected. In the sample code the entire event log is iterated when the
Read method is invoked.
Fortunately the exercise in frustration was offset by the learning and
understanding experience.
regards
A.G.
On Tue, 13 Dec 2005 18:37:43 -0500, Registered User
<n4jvp@.ix.netcom.com> wrote:
>I am trying to write my first data processing extension. The project
>is based upon the Event Log example in chapter 13 of Hitchhiker's
>Guide to SQL Server 2000 Reporting Services. The assembly has been
>copied to the various directories and the various config files have
>been modified.
>The extension is used in a report project and a shared datasource is
>created using the extension. When a report's dataset is created the
>Fields window in the IDE is not populated. When the command is run in
>the data window of the designer a null pointer error occurs. In the
>preview window the error indicates the connection is not valid. This
>project is written in C# and the supplied sample is written in VB.NET.
>The same error occurs using the VB assemblies.
>The "connection not valid" exception is generated from command class'
>ExecuteReader method. The connection member is found to be null w/in
>the method. In the overloaded c'tor where the connection argument is
>assigned to the connection member, the argument is not null and the
>member is not null after it has been assigned to. I am baffled as to
>what/why/how this occuring. Suggestion?
>Equally or more important how does one setup a data processing
>extension project for debugging?
>thank you
>A.G.