Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, March 30, 2012

Problem with checkpoints in SS2005 - Help is appreciated

Hello All,
I am having problems with the contention caused by checkpoints as I
migrated from SQL Server 2000 to SQL Server 2005. The same code, the
same database, tha same machine, the same load, but much worse
performance.
Do you know of any changes in the way checkpoints are performed in SQL
Server 2005?
In particular, any change in the locking behavior?
Your help is appreciated.
Kind regards
CD
CD
How do you know that is CHECKPOINT ? Have you run Profiler? Did you update
statistics after upgrading?
"CD" <crbd98@.yahoo.com> wrote in message
news:1179976388.257189.15410@.b40g2000prd.googlegro ups.com...
> Hello All,
> I am having problems with the contention caused by checkpoints as I
> migrated from SQL Server 2000 to SQL Server 2005. The same code, the
> same database, tha same machine, the same load, but much worse
> performance.
> Do you know of any changes in the way checkpoints are performed in SQL
> Server 2005?
> In particular, any change in the locking behavior?
> Your help is appreciated.
> Kind regards
> CD
>
|||Did you guys adjust the recovery interval?
Run a recompile on all stored procedures
But indeed monitor with profiler!
sql

Problem with checkpoints in SS2005 - Help is appreciated

Hello All,
I am having problems with the contention caused by checkpoints as I
migrated from SQL Server 2000 to SQL Server 2005. The same code, the
same database, tha same machine, the same load, but much worse
performance.
Do you know of any changes in the way checkpoints are performed in SQL
Server 2005?
In particular, any change in the locking behavior?
Your help is appreciated.
Kind regards
CDCD
How do you know that is CHECKPOINT ? Have you run Profiler? Did you update
statistics after upgrading?
"CD" <crbd98@.yahoo.com> wrote in message
news:1179976388.257189.15410@.b40g2000prd.googlegroups.com...
> Hello All,
> I am having problems with the contention caused by checkpoints as I
> migrated from SQL Server 2000 to SQL Server 2005. The same code, the
> same database, tha same machine, the same load, but much worse
> performance.
> Do you know of any changes in the way checkpoints are performed in SQL
> Server 2005?
> In particular, any change in the locking behavior?
> Your help is appreciated.
> Kind regards
> CD
>|||Did you guys adjust the recovery interval?
Run a recompile on all stored procedures
But indeed monitor with profiler!

Problem with checkpoints in SS2005 - Help is appreciated

Hello All,
I am having problems with the contention caused by checkpoints as I
migrated from SQL Server 2000 to SQL Server 2005. The same code, the
same database, tha same machine, the same load, but much worse
performance.
Do you know of any changes in the way checkpoints are performed in SQL
Server 2005?
In particular, any change in the locking behavior?
Your help is appreciated.
Kind regards
CDCD
How do you know that is CHECKPOINT ? Have you run Profiler? Did you update
statistics after upgrading?
"CD" <crbd98@.yahoo.com> wrote in message
news:1179976388.257189.15410@.b40g2000prd.googlegroups.com...
> Hello All,
> I am having problems with the contention caused by checkpoints as I
> migrated from SQL Server 2000 to SQL Server 2005. The same code, the
> same database, tha same machine, the same load, but much worse
> performance.
> Do you know of any changes in the way checkpoints are performed in SQL
> Server 2005?
> In particular, any change in the locking behavior?
> Your help is appreciated.
> Kind regards
> CD
>|||Did you guys adjust the recovery interval?
Run a recompile on all stored procedures
But indeed monitor with profiler!

Problem with BULK INSERT ASCII file into nvarchar column

Hi,

I have a problem with BULK INSERT. I created the following table:

Code Snippet

create table Test
(id char(4), name nvarchar(16), last char(1))

I am trying to bulk insert data from ASCII (not unicode) file with only two rows:

0011First name
0018Second name

Since it is a fixed length file, I am using the following format file:

Code Snippet

8.0
3
1 SQLCHAR 0 4 "" 1 ID HEBREW_CI_AS
2 SQLCHAR 0 16 "" 2 NAME HEBREW_CI_AS
3 SQLCHAR 0 0 "\r\n" 3 Last HEBREW_CI_AS

With bcp utility everything works just fine!

Code Snippet

bcp Demo.dbo.test in c:\test -T -f c:\test.fmt

But when I use BULK INSERT in the following form:

Code Snippet

BULK INSERT Test FROM 'c:\Test'
WITH
(
FORMATFILE='c:\Test.fmt',
CODEPAGE='OEM'
);

I am getting error

Server: Msg 4863, Level 16, State 1, Line 1
Bulk insert data conversion error (truncation) for row 1, column 2 (name).

Now, one interesting thing: if I change the name field from nvarchar to varchar, it is working with BULK INSERT as well.

Can anybody explain what is going on here?

I am using MS SQL 2000 and MSDE

Thanks in advance,

Eugene.

Another thing is that if I set the format file to specify row delimiter for that nvarchar field, it will also work.

Code Snippet

8.0
2
1 SQLCHAR 0 4 "" 1 ID HEBREW_CI_AS
2 SQLCHAR 0 16 "\r\n" 2 NAME HEBREW_CI_AS

But then in the real system i can't have multiple fields within the file...

|||

On SQL2005 the problem does not exist! Then it seems like a bug in SQL2000!

sql

Wednesday, March 28, 2012

problem with bit datatype conversion

Hi All,

I have create following table and inserted few records

Code Snippet

USE



GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_position](
[part] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[price] [money] NOT NULL,
[opt] [bit] NOT NULL
) ON [PRIMARY]

I am executing following procedure to update the table.

Code Snippet

USE



GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PROC1] ( @.part varchar(20), @.PRICE MONEY, @.OPT BIT )
AS
BEGIN
declare @.sSQL as nvarchar(max);
SET @.sSQL = 'update tbl_position set opt=@.OPT,price=@.PRICE WHERE part = '+ @.part;
exec sp_executesql @.sSQL
END


ex:

Code Snippet

exec PROC1 1,2.50,0

but I am getting following error

Code Snippet

Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@.OPT".


I am struck up with this query .

Please Help me regarding this issue.


Regards
Gomaz

Code Snippet

CREATE PROCEDURE [dbo].[PROC1] ( @.part varchar(20), @.PRICE MONEY, @.OPT BIT )

AS

BEGIN

declare @.sSQL as nvarchar(max);

SET @.sSQL = 'update tbl_position set opt=' +cast(@.OPT as char(1) )+',price='+@.PRICE+' WHERE part = '+ @.part;

exec sp_executesql @.sSQL

END

sp_executesql execute query in different bacth. As you couldn't use opt=@.OPT

Monday, March 26, 2012

Problem with Array of strings in SQL...

I am using the code given below which works fine for array of integers, can anyone help me to convert this code to use it for array of strings
basically i want to store the search keywords in the array of strings and use them in the stored procedure.
CREATE Function fnSplitter (@.IDs Varchar(100) )
Returns @.Tbl_IDs Table (ID Int) As

Begin
-- Append comma
Set @.IDs = @.IDs + ','
-- Indexes to keep the position of searching
Declare @.Pos1 Int
Declare @.pos2 Int

-- Start from first character
Set @.Pos1=1
Set @.Pos2=1

While @.Pos1<Len(@.IDs)
Begin
Set @.Pos1 = CharIndex(',',@.IDs,@.Pos1)
Insert @.Tbl_IDs Select Cast(Substring(@.IDs,@.Pos2,@.Pos1-@.Pos2) As Int)
-- Go to next non comma character
Set @.Pos2=@.Pos1+1
-- Search from the next charcater
Set @.Pos1 = @.Pos1+1
End
Return
End
CREATE PROCEDURE spSelectEmployees(@.IDs Varchar(100)) AS
Select * From employees Where employeeid In (Select ID From fnSplitter(@.IDs))

Exec spSelectEmployees '1,4,5,7,9'

I want replace the above Exec statement withExec spSelectEmployees 'sap, abap, hr, ... ' in the JobPosition Column of Employees if possible, i've been trying to change it but its not working out
Thanks in Advance

Check out the split function Bilal posted in this thread:http://forums.asp.net/997824/ShowPost.aspx
|||I checked Haidar Bilals code but it returns only a specific item in the given string based on the position specified.
But in my case i got only one string which goes like this 'sap, abap, consultant,.. , ...' which i need to use them in the stored procedure .
I am actuallycreating a search page for jobs and when a person enters different keywords in the textbox i'm storing them in the array.
Here is the previous part of my code
string strsearch = txtsearch.Text;
string []items = strsearch.Split();
Session["items"]= items;
and on the other page i'm using the session items
string []items = (string[])Session["Items"];


|||

savvy wrote:

I checked Haidar Bilals code but it returns only aspecific item in the given string based on the position specified.


Ack, sorry, I picked the wrong post. There are many posts where asplit function has been posted. There's one that Dinakar postedin this thread:http://forums.asp.net/989365/ShowPost.aspx
|||Thanks for ur fast reply
i used this code
CREATE FUNCTION dbo.Split1
(
@.RowData nvarchar(2000),
@.SplitOn nvarchar(5)
)
RETURNS @.RtnValue table
(
Id int identity(1,1),
Data nvarchar(100)
)
AS
BEGIN
Declare @.Cnt int
Set @.Cnt = 1
While (Charindex(@.SplitOn,@.RowData)>0)
Begin
Insert Into @.RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@.RowData,1,Charindex(@.SplitOn,@.RowData)-1)))
Set @.RowData = Substring(@.RowData,Charindex(@.SplitOn,@.RowData)+1,len(@.RowData))
Set @.Cnt = @.Cnt + 1
End
Insert Into @.RtnValue (data)
Select Data = ltrim(rtrim(@.RowData))
Return
END
Declare @.list varchar(200)
set @.list = 'SAP MM Support Consultant, Managing Consultant SAP FI/C '
Select * from JobDetails where JobPosition in (Select Data from dbo.Split1(@.list, ','))
I am getting the results but the problem is i have to give the exact word or phrase inorder to get the results, actually i want to enter just 'sap, consultant' and get the same result .. is it possible?
Thanx in Advance
|||You could try your query like this:

SELECT @.list = 'SAP, Consultant'
SELECT
*
FROM
JobDetails AS J
INNER JOIN
dbo.Split1(@.list, ',') AS S ON J.JobPosition LIKE '%' + S.Data + '%'


|||Declare @.list varchar(200)
set @.list = 'abap,hr,sap'
SELECT Distinct J.* FROM JobDetails AS J inner join dbo.Split1(@.list, ',') AS S ON J.JobPosition LIKE '%' + S.Data + '%'
I used this code finally it works fine. Thank u very much Terri Morton for all your help and interestsql

Wednesday, March 21, 2012

Problem with a select in a stored procedure

Does anybody know what is wrong with this code from a stored procedure:
DECLARE tables_cursor CURSOR FOR
SELECT tf_change_out_id, destination, re_table, date_in
FROM tf_change_out_table
WHERE date_out = NULL
ORDER BY tf_change_out_id

Here is the error I'm getting:
Error 107: The column prefix 'tf_change_out_table' does not match with a table name or alias name used in the query.Perhaps there's something before the cursor declaration that results in the error below. If you'd select the cursor-declaration, and parse it, is there an error message?|||Silly me! The error was further down the code. Why can't they give line numbers with all the errors?|||That woud make it too easy, and then everyone would think they could write SQL :D


Besides ... if it was hard to write, it should be hard to read ;)

Problem with 64-bit ODBC code and SQLConnect and SQLWCHAR

Hi all,
I'm trying to test some 64-bit ODBC stuff and I'm running into a slight
problem. First, my configuration.
Windows XP x64
VS.Net 2005 Beta 2
SQL Server 2005 CTP
So, I have built and tested other 64 bit apps so I know that things are all
working, but now I'm trying to test ODBC and I'm running into a problem. I
have the following code :
SQLCHAR Database[MAXBUFLEN]; // = "Cloud";
SQLCHAR User[MAXBUFLEN]; // = "fred";
SQLCHAR Pass[MAXBUFLEN]; // = "me";
sprintf ((char *)Database, "%s", "Cloud");
sprintf ((char *)User, "%s", "fred");
sprintf ((char *)Pass, "%s", "me");
retcode = SQLConnect(hdbc1, Database, SQL_NTS,
User, SQL_NTS, Pass, SQL_NTS);
If I execute this code as part of a little test program on my 32 bit box, it
connects just fine. Now, to get this code to compile on the 64-bit box, I
have to cast the string variable with (SQLWCHAR *) like this.
retcode = SQLConnect(hdbc1, (SQLWCHAR *)Database, SQL_NTS,
(SQLWCHAR *)User, SQL_NTS, (SQLWCHAR *)Pass, SQL_NTS);
So it compiles, but when I run it, I get an error back. If I take a look
at what (SQLWCHAR *)Database produces, its some unreadable junk. If I turn
on ODBC logging and then after the SQLConnect call take a look at the log,
where I should see the database for instance, I see just random characters.
So, what gives ? Do I have to do something special when working with
SQLWCHAR ?
Thanks for any help anyone can give me.
Nick
Hi
SQL Server 2005 CTP questions to the community newsgroups:
http://communities.microsoft.com/new...r2005&slcid=us
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Nick Palmer" <nick@.kcicorp.com> wrote in message
news:11i480ff7qiikf9@.corp.supernews.com...
> Hi all,
> I'm trying to test some 64-bit ODBC stuff and I'm running into a slight
> problem. First, my configuration.
> Windows XP x64
> VS.Net 2005 Beta 2
> SQL Server 2005 CTP
> So, I have built and tested other 64 bit apps so I know that things are
> all
> working, but now I'm trying to test ODBC and I'm running into a problem.
> I
> have the following code :
> SQLCHAR Database[MAXBUFLEN]; // = "Cloud";
> SQLCHAR User[MAXBUFLEN]; // = "fred";
> SQLCHAR Pass[MAXBUFLEN]; // = "me";
> sprintf ((char *)Database, "%s", "Cloud");
> sprintf ((char *)User, "%s", "fred");
> sprintf ((char *)Pass, "%s", "me");
> retcode = SQLConnect(hdbc1, Database, SQL_NTS,
> User, SQL_NTS, Pass, SQL_NTS);
> If I execute this code as part of a little test program on my 32 bit box,
> it
> connects just fine. Now, to get this code to compile on the 64-bit box, I
> have to cast the string variable with (SQLWCHAR *) like this.
> retcode = SQLConnect(hdbc1, (SQLWCHAR *)Database, SQL_NTS,
> (SQLWCHAR *)User, SQL_NTS, (SQLWCHAR *)Pass, SQL_NTS);
> So it compiles, but when I run it, I get an error back. If I take a look
> at what (SQLWCHAR *)Database produces, its some unreadable junk. If I
> turn
> on ODBC logging and then after the SQLConnect call take a look at the log,
> where I should see the database for instance, I see just random
> characters.
> So, what gives ? Do I have to do something special when working with
> SQLWCHAR ?
> Thanks for any help anyone can give me.
> Nick
>

Problem with 64-bit ODBC code and SQLConnect and SQLWCHAR

Hi all,
I'm trying to test some 64-bit ODBC stuff and I'm running into a slight
problem. First, my configuration.
Windows XP x64
VS.Net 2005 Beta 2
SQL Server 2005 CTP
So, I have built and tested other 64 bit apps so I know that things are all
working, but now I'm trying to test ODBC and I'm running into a problem. I
have the following code :
SQLCHAR Database[MAXBUFLEN]; // = "Cloud";
SQLCHAR User[MAXBUFLEN]; // = "fred";
SQLCHAR Pass[MAXBUFLEN]; // = "me";
sprintf ((char *)Database, "%s", "Cloud");
sprintf ((char *)User, "%s", "fred");
sprintf ((char *)Pass, "%s", "me");
retcode = SQLConnect(hdbc1, Database, SQL_NTS,
User, SQL_NTS, Pass, SQL_NTS);
If I execute this code as part of a little test program on my 32 bit box, it
connects just fine. Now, to get this code to compile on the 64-bit box, I
have to cast the string variable with (SQLWCHAR *) like this.
retcode = SQLConnect(hdbc1, (SQLWCHAR *)Database, SQL_NTS,
(SQLWCHAR *)User, SQL_NTS, (SQLWCHAR *)Pass, SQL_NTS);
So it compiles, but when I run it, I get an error back. If I take a look
at what (SQLWCHAR *)Database produces, its some unreadable junk. If I turn
on ODBC logging and then after the SQLConnect call take a look at the log,
where I should see the database for instance, I see just random characters.
So, what gives ? Do I have to do something special when working with
SQLWCHAR ?
Thanks for any help anyone can give me.
NickHi
SQL Server 2005 CTP questions to the community newsgroups:
http://communities.microsoft.com/ne...lcid=us

--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Nick Palmer" <nick@.kcicorp.com> wrote in message
news:11i480ff7qiikf9@.corp.supernews.com...
> Hi all,
> I'm trying to test some 64-bit ODBC stuff and I'm running into a slight
> problem. First, my configuration.
> Windows XP x64
> VS.Net 2005 Beta 2
> SQL Server 2005 CTP
> So, I have built and tested other 64 bit apps so I know that things are
> all
> working, but now I'm trying to test ODBC and I'm running into a problem.
> I
> have the following code :
> SQLCHAR Database[MAXBUFLEN]; // = "Cloud";
> SQLCHAR User[MAXBUFLEN]; // = "fred";
> SQLCHAR Pass[MAXBUFLEN]; // = "me";
> sprintf ((char *)Database, "%s", "Cloud");
> sprintf ((char *)User, "%s", "fred");
> sprintf ((char *)Pass, "%s", "me");
> retcode = SQLConnect(hdbc1, Database, SQL_NTS,
> User, SQL_NTS, Pass, SQL_NTS);
> If I execute this code as part of a little test program on my 32 bit box,
> it
> connects just fine. Now, to get this code to compile on the 64-bit box, I
> have to cast the string variable with (SQLWCHAR *) like this.
> retcode = SQLConnect(hdbc1, (SQLWCHAR *)Database, SQL_NTS,
> (SQLWCHAR *)User, SQL_NTS, (SQLWCHAR *)Pass, SQL_NTS);
> So it compiles, but when I run it, I get an error back. If I take a look
> at what (SQLWCHAR *)Database produces, its some unreadable junk. If I
> turn
> on ODBC logging and then after the SQLConnect call take a look at the log,
> where I should see the database for instance, I see just random
> characters.
> So, what gives ? Do I have to do something special when working with
> SQLWCHAR ?
> Thanks for any help anyone can give me.
> Nick
>

Tuesday, March 20, 2012

PROBLEM WIHT OPENROWSET FUNCTION

HI FRIENDS THIS IS AMIT. THE PROBLEM IS I M TRYING TO EXPORT DATA FROM SQL SERVER TABLE TO EXCEL FILE USING FOLLOWING CODE SNIPPET,

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 7.0;Database=c:\testing.xls;',
'SELECT * FROM [Sheet1$]') select * from TABLE1

BUT IT IS SHOWING SOME ERROR WHICH IS AS FOLLOWS,

Invalid object name 'OPENROWSET'.

I FOUND OPENROWSET FUNCTION IN T-SQL REFERENCE BUT STILL THE ABOVE MESSAGE IS COMING PLS HELP IN THIS MATTER ASAP.

REGARDS,

AMIT.

What version of SQL Server are you using (show the output of SELECT @.@.VERSION)?

Steve Kass
Drew University
http://www.stevekass.com|||

Make sure you have "Ad Hoc Remote Queries" enabled for your instance.

|||Kindly provide the version of the SQL Server you are using, it should ideally work without problem in SQL Server 2000 and above. You can however try the same using DTS (Data Transformation Services)|||Excel 7.0??

Try Excel 5.0 or Excel 8.0

Monday, March 12, 2012

Problem while accessing sysprocesses table

Hi all,
I am facing one wired problem with sysprocesses table of system table.
What i am doing is executing some stored procedures though code written
in dot net.
What i want is to check those stored procedure's id in sysprocesses
table and then update status in one user defined table.
So when user started say 4 stored procedure. and when i check
sysprocesses table even if my 4 stored procedures are running those are
not getting displayed in sysprocesses table.
I am checking each processid and all my stored proceudures are heavy
running means there is no possibility that they will complete execution
within say 1 to 2 min.
So my question is why sysprocess table is not giving me information
about those procedures which i am running.
Can some one shed some light on it.
Any help will be truely appreciated.
Thanks in advance.try
sp_who2
and see if there are processes running from the machine which has the dotnet
code running.|||As you mentioned you execute the sp though code written in dot net, it
won't show directly in the sysprocesses table as a sp in the cmd field.
If you execute the sp in QA, you will then see it clearly.
Alternatively, run the profiler to capture the action.
Mel

Problem when rebuild system databases for a clustered instance of

Has anyone rebuilt system databases for a SQL2005 clustered instance?
I have followed the code from "To rebuild system databases for a clustered."
section at http://msdn2.microsoft.com/en-us/library/ms144259.aspx, and keep
getting message saying to add more parameters. I added the parameter
whenever it required, "Group", then "addnode", even INSTALLSQLDATADIR = "S:\"
which data should go.
The summary.txt says "Setup succeeded with the installation". But in the
files\setup_*_core.log for both node2, I have this error:
Error: Action "LaunchLocalBootstrapAction" threw an exception during
execution. Error information reported during run:
"C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\setup.exe"
finished and returned: 0
Aborting queue processing as nested installer has completed
Message pump returning: 0
I want to know whether anyone has similar problem or succeed when rebuild
system DBs for a cluster.
What are all the parameters needed for rebuilding sys databases on a
cluster? Is there anything should be aware of?
Hi Julia
Did you manage to resolve this problem? I am experiencing exactly the
same thing .
Cheers
Jesse
*** Sent via Developersdex http://www.codecomments.com ***
|||No. I have contacted Microsoft but no answer. I would recommend you report
this problem as well to them and get them to look into it.
"Jesse Easton" wrote:

>
> Hi Julia
> Did you manage to resolve this problem? I am experiencing exactly the
> same thing .
> Cheers
> Jesse
> *** Sent via Developersdex http://www.codecomments.com ***
>

Friday, March 9, 2012

Problem when i am using RSClientPrint Active X

Hi ,

I m using rsclientscript in my application..i m using the following code in <script>

function Print()
{
RSClientPrint.MarginLeft = 12.7;
RSClientPrint.MarginTop = 12.7;
RSClientPrint.MarginRight = 12.7;
RSClientPrint.MarginBottom = 12.7;
RSClientPrint.Culture = 1033;
RSClientPrint.UICulture = 9;
RSClientPrint.Print('http://localhost/Reports/Pages/Report.aspx?ItemPath', '=%2fTestMonday%2fSrCorpLogo&CorporationId=2', 'Employee_Sales_Summary')
}
</script>

I m calling this script when user clicks the button in the webpage..

I m getting the dialog box properly..In that if i click preview button i m getting the following error

"An error occured trying to render the report. (0x80004005)"

Please help me out ..Very Urgent Issue..

Thanks in Advance..

Bhoopathi..

I was trying this out just yesterday and got the same problem.

I believe the print control can't find your report on the report server. I fixed my problem by playing with the paths I passed in to the Print function.

Try this... without knowing much about your environment...

* The first argument should be the url of the report server...

* The second argument should be the name of the report along with any report parameters..

I'm assuming by the path you provided in your example you have a folder called TestMonday with a report called SrCorpLogo.

* The third argument should be the name of the report by itself.

RSClientPrint.Print('http://localhost/reportserver', '/TestMonday/SrCorpLogo&CorporationId=2', 'SrCorpLogo')

Plug that in and see what happens. Hope this helps.

|||thnks for ur reply JeffZ....|||I think it's a matter of authentication am searching, i'll post a solution as soon as i can find, if any one has a solution pla don't hesitate to post it

Wednesday, March 7, 2012

Problem w/ Script Task accessing Directory Services

Using the example from SS online books:

The code is this:

Public Sub Main()

Dim directory As DirectoryServices.DirectorySearcher

Dim result As DirectoryServices.SearchResult

Dim email As String

email = Dts.Variables("email").Value.ToString

Try

directory = New _

DirectoryServices.DirectorySearcher("(mail=" & email & ")")

result = directory.FindOne

Dts.Variables("name").Value = _

result.Properties("name").ToString()

Dts.TaskResult = Dts.Results.Success

Catch ex As Exception

Dts.Events.FireError(0, _

"Script Task Example", _

ex.Message & ControlChars.CrLf & ex.StackTrace, _

String.Empty, 0)

Dts.TaskResult = Dts.Results.Failure

End Try

Dts.TaskResult = Dts.Results.Success

End Sub

End Class

My problem is I'm not getting a value for 'Name' instead when I display in a dataflow task (using dataviewer)following the script task the value of Name = 'System.DirectoryServices.ResultPropertyValueCollection'

It's seems like it is telling me its property not the value. I'm not a VB/.Net developer so I'm just guessing as to what the value means.

Any help would be appreciated.

thanks

I'm nod directory services expert, but from MSDN, the indexer of ResultPropertyCollection is declared as

Public ReadOnly Default Property Item ( _ name As String _ ) As ResultPropertyValueCollection

I.e. result.Properties("name") returns a collecions of properties, not the value.

|||

Found additional examples of how to do this and got it working

thanks

Problem viewing report based on analysis services

I am using using some code which Implements IReportServerCredentials (see
the object below) to pass credentials to a non local report server. This
works fine and my reportviewer can get it's report from a non local server.
When the report uses Analysis Services it displays the parameters part of
the report viewer so I know it is getting as far as the report server but
when I press view report I doesn't display anything, not even an error. I
have tried adding the user I am logging as to the roles within the analysis
Services project it is based on but with no luck. I have included the code
in case anyone finds it helpful. Can anyone help?
Dim cred As New ReportServerCredentials("username", "password", "domain")
ReportViewer1.ServerReport.ReportServerCredentials = cred
Imports Microsoft.VisualBasic
Imports Microsoft.Reporting.WebForms
Imports System.Net
Public Class reportingservices
End Class
<Serializable()> _
Public Class ReportServerCredentials
Implements IReportServerCredentials
Private _userName As String
Private _password As String
Private _domain As String
Public Sub New(ByVal userName As String, ByVal password As String, ByVal
domain As String)
_userName = userName
_password = password
_domain = domain
End Sub
Public ReadOnly Property ImpersonationUser() As
System.Security.Principal.WindowsIdentity Implements
Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End Property
Public ReadOnly Property NetworkCredentials() As ICredentials Implements
Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
Get
Return New NetworkCredential(_userName, _password, _domain)
End Get
End Property
Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie,
ByRef userName As String, ByRef password As String, ByRef authority As
String) As Boolean Implements
Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
userName = _userName
password = _password
authority = _domain
Return Nothing
End Function
End ClassIn this instance are you trying to access the report in the following
situation:
client accessing report (machine1) -> Report Server (machine 2) -> Analysis
Services (machine 3)?
If so then it is most likely a kerberos authentication issue due to the
"double hop" you are experiencing.
For more information on enabling this check the following article:
http://support.microsoft.com/kb/917409/en-us
SQL Server Developer Support Engineer
"Fresno Bob" wrote:
> I am using using some code which Implements IReportServerCredentials (see
> the object below) to pass credentials to a non local report server. This
> works fine and my reportviewer can get it's report from a non local server.
> When the report uses Analysis Services it displays the parameters part of
> the report viewer so I know it is getting as far as the report server but
> when I press view report I doesn't display anything, not even an error. I
> have tried adding the user I am logging as to the roles within the analysis
> Services project it is based on but with no luck. I have included the code
> in case anyone finds it helpful. Can anyone help?
> Dim cred As New ReportServerCredentials("username", "password", "domain")
> ReportViewer1.ServerReport.ReportServerCredentials = cred
>
> Imports Microsoft.VisualBasic
> Imports Microsoft.Reporting.WebForms
> Imports System.Net
>
>
> Public Class reportingservices
> End Class
>
> <Serializable()> _
> Public Class ReportServerCredentials
> Implements IReportServerCredentials
> Private _userName As String
> Private _password As String
> Private _domain As String
> Public Sub New(ByVal userName As String, ByVal password As String, ByVal
> domain As String)
> _userName = userName
> _password = password
> _domain = domain
> End Sub
> Public ReadOnly Property ImpersonationUser() As
> System.Security.Principal.WindowsIdentity Implements
> Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
> Get
> Return Nothing
> End Get
> End Property
> Public ReadOnly Property NetworkCredentials() As ICredentials Implements
> Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
> Get
> Return New NetworkCredential(_userName, _password, _domain)
> End Get
> End Property
> Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie,
> ByRef userName As String, ByRef password As String, ByRef authority As
> String) As Boolean Implements
> Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
> userName = _userName
> password = _password
> authority = _domain
> Return Nothing
> End Function
> End Class
>
>

Problem Using XML BASE64 encoding & SQL Server

Here is what I am trying to do.

I allow users to upload images from client side. This is the code I m using to load image into a client side xml document element

var node1 = xmlData.createElement("PHOTO");
node1.dataType = "bin.base64";
// Open stream object and read source file
adoStream.Type = 1; // 1=adTypeBinary
adoStream.Open();
adoStream.LoadFromFile(filename);

// Store file content and filename into XML nodes
node1.nodeTypedValue = adoStream.Read(-1); // -1=adReadAll
document.all("INVST_PHOTO").src = adoStream.Read(-1);
node2.nodeTypedValue = filename;

Now after that I extract this Image and insert it into Sql server using a stored procedure.

Dim ImgBuff() As Byte

ImgBuff = objDOMDocument.selectSingleNode("SACWIS/INVST/INVST_PHOTO/PHOTO").Text

' Add null termination:
ReDim Preserve ImgBuff(0 To UBound(ImgBuff) + 2) As Byte

' Get the pointer to the string:
Dim lPtrString As Long
lPtrString = VarPtr(ImgBuff(0))

objCmd.Parameters("@.pIMG_PHOTO").AppendChunk ImgBuff().

I am Sucessfully able to store it in the database fileld type of Image. Now I am using XML: to retrieve images from the database. Here is how the SQL looks like

SELECT
1 AS TAG, NULL AS PARENT,
IMG_PHOT AS [PHOTO!1!PHOTO!ELEMENT]
FROM PHOTO
FOR XML EXPLICIT , BINARY BASE64
The problem I am runing into is that content of the IMG_PHOTO are not the same after saving and retreival.

Here is how the contents are prior to inserting into database

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoKDBand here is how they look after retrieval

LwA5AGoALwA0AEEAQQBRAFMAawBaAEoAUgBnAEEAQgBBAGcAQQBBAFoAQQBCAGsAQQBBAEQALwA3AEEAQQBSAFIASABWAGoAYQAzAGsAQQB

I expected them to look same. I guess what I am doing is encoding the contents twice once I load it and once I am retreiving it from xml. Can please somebody help me out with this so that I can have the same content on both ocassion.

I am using Javascript/VB6/SQLServer 2000

I resolved it Instead of using

ImgBuff = objDOMDocument.selectSingleNode("SACWIS/INVST/INVST_PHOTO/PHOTO").Tex

I shoudl have used it Instead of using

ImgBuff = objDOMDocument.selectSingleNode("SACWIS/INVST/INVST_PHOTO/PHOTO").nodeTypeValue

which gives me base64 encoding data. VB string gives us Unicode data.

Problem Using XML BASE64 encoding & SQL Server

Here is what I am trying to do.

I allow users to upload images from client side. This is the code I m using to load image into a client side xml document element

var node1 = xmlData.createElement("PHOTO");
node1.dataType = "bin.base64";
// Open stream object and read source file
adoStream.Type = 1; // 1=adTypeBinary
adoStream.Open();
adoStream.LoadFromFile(filename);

// Store file content and filename into XML nodes
node1.nodeTypedValue = adoStream.Read(-1); // -1=adReadAll
document.all("INVST_PHOTO").src = adoStream.Read(-1);
node2.nodeTypedValue = filename;

Now after that I extract this Image and insert it into Sql server using a stored procedure.

Dim ImgBuff() As Byte

ImgBuff = objDOMDocument.selectSingleNode("SACWIS/INVST/INVST_PHOTO/PHOTO").Text

' Add null termination:
ReDim Preserve ImgBuff(0 To UBound(ImgBuff) + 2) As Byte

' Get the pointer to the string:
Dim lPtrString As Long
lPtrString = VarPtr(ImgBuff(0))

objCmd.Parameters("@.pIMG_PHOTO").AppendChunk ImgBuff().

I am Sucessfully able to store it in the database fileld type of Image. Now I am using XML: to retrieve images from the database. Here is how the SQL looks like

SELECT
1 AS TAG, NULL AS PARENT,
IMG_PHOT AS [PHOTO!1!PHOTO!ELEMENT]
FROM PHOTO
FOR XML EXPLICIT , BINARY BASE64
The problem I am runing into is that content of the IMG_PHOTO are not the same after saving and retreival.

Here is how the contents are prior to inserting into database

/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoKDBand here is how they look after retrieval

LwA5AGoALwA0AEEAQQBRAFMAawBaAEoAUgBnAEEAQgBBAGcAQQBBAFoAQQBCAGsAQQBBAEQALwA3AEEAQQBSAFIASABWAGoAYQAzAGsAQQB

I expected them to look same. I guess what I am doing is encoding the contents twice once I load it and once I am retreiving it from xml. Can please somebody help me out with this so that I can have the same content on both ocassion.

I am using Javascript/VB6/SQLServer 2000

I resolved it Instead of using

ImgBuff = objDOMDocument.selectSingleNode("SACWIS/INVST/INVST_PHOTO/PHOTO").Tex

I shoudl have used it Instead of using

ImgBuff = objDOMDocument.selectSingleNode("SACWIS/INVST/INVST_PHOTO/PHOTO").nodeTypeValue

which gives me base64 encoding data. VB string gives us Unicode data.

Saturday, February 25, 2012

Problem using SelectParameters with Oracle Queries

Hi,

I have a GridView which is bound to a SqlDataSource that connects to Oracle. Here's the code:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:OracleConnectionString%>" ProviderName="<%$ ConnectionStrings:OracleConnectionString.ProviderName%>" SelectCommand="SELECT QUIZ.TITLE FROM QUIZ WHERE (QUIZ.USERNAME = @.UserName)"
<SelectParameters>
<asp:SessionParameter Name="UserName" SessionField="currentUser" Type="String" />
</SelectParameters
</asp:SqlDataSource>

As you can see I'm trying to pass the value of the "currentUser" session variable to the query. I get an error message "ORA-xxx Illegal name/variable". Where am I going wrong? I tested the connection by placing a specific value instead of the "@.UserName" and it worked.

That is because Oracle Server doesn't use @. as a prefix for a parameter, it uses a colon (:).

Take a look at this example:

http://www.oracle.com/technology/oramag/oracle/05-sep/o55odpnet.html

Problem using EXEC() to run DBCC DBREINDEX

I am trying to run DBCC DBREINDEX using EXEC(), code is below.
Based upon the error message at the bottom, the @.currenttable variable
receives the value 1 but when @.currenttable is referenece in the DBCC
statement, the value isn't there. Can anyone tell me what I'm doing wrong?
declare @.sqltest varchar(40), @.currenttable int
set @.currenttable = (select table_id from Table_Space where table_id = 1)
set @.sqltest = 'DBCC DBREINDEX(''@.currenttable'','''',75)'
print @.currenttable
print @.sqltest
EXEC(@.sqltest)
Below is the message I get:
1
DBCC DBREINDEX('@.currenttable','',75)
Server: Msg 2501, Level 16, State 1, Line 1
Could not find a table or object named '@.currenttable'. Check sysobjects.nosurfdj,
DBCC DBREINDEX expects a table name and there is not table named
'@.currenttable'.
declare @.sqltest varchar(40), @.currenttable int
declare @.tn sysname
set @.tn = (select table_name from Table_Space where table_id = 1)
set @.sqltest = 'DBCC DBREINDEX(''' + @.tn + ''','''',75)'
print @.currenttable
print @.sqltest
EXEC(@.sqltest)
go
AMB
"nosurfdj" wrote:

> I am trying to run DBCC DBREINDEX using EXEC(), code is below.
> Based upon the error message at the bottom, the @.currenttable variable
> receives the value 1 but when @.currenttable is referenece in the DBCC
> statement, the value isn't there. Can anyone tell me what I'm doing wrong
?
> declare @.sqltest varchar(40), @.currenttable int
> set @.currenttable = (select table_id from Table_Space where table_id = 1)
> set @.sqltest = 'DBCC DBREINDEX(''@.currenttable'','''',75)'
> print @.currenttable
> print @.sqltest
> EXEC(@.sqltest)
> Below is the message I get:
> 1
> DBCC DBREINDEX('@.currenttable','',75)
> Server: Msg 2501, Level 16, State 1, Line 1
> Could not find a table or object named '@.currenttable'. Check sysobjects.
>|||Quote problems around ''@.currenttable''.
Try:
'DBCC DBREINDEX(' + @.currenttable + ','''',75)'
--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"nosurfdj" <nosurfdj@.discussions.microsoft.com> wrote in message news:2406FBD3-FD2A-4F69-8A
8E-F446DC1473BF@.microsoft.com...
>I am trying to run DBCC DBREINDEX using EXEC(), code is below.
> Based upon the error message at the bottom, the @.currenttable variable
> receives the value 1 but when @.currenttable is referenece in the DBCC
> statement, the value isn't there. Can anyone tell me what I'm doing wrong
?
>
> declare @.sqltest varchar(40), @.currenttable int
> set @.currenttable = (select table_id from Table_Space where table_id = 1)
> set @.sqltest = 'DBCC DBREINDEX(''@.currenttable'','''',75)'
> print @.currenttable
> print @.sqltest
> EXEC(@.sqltest)
>
> Below is the message I get:
> 1
> DBCC DBREINDEX('@.currenttable','',75)
> Server: Msg 2501, Level 16, State 1, Line 1
> Could not find a table or object named '@.currenttable'. Check sysobjects.
>|||I knew it was going to be something simple.
Thanks for your help-that did it.
"Alejandro Mesa" wrote:
> nosurfdj,
> DBCC DBREINDEX expects a table name and there is not table named
> '@.currenttable'.
> declare @.sqltest varchar(40), @.currenttable int
> declare @.tn sysname
> set @.tn = (select table_name from Table_Space where table_id = 1)
> set @.sqltest = 'DBCC DBREINDEX(''' + @.tn + ''','''',75)'
> print @.currenttable
> print @.sqltest
> EXEC(@.sqltest)
> go
>
> AMB
> "nosurfdj" wrote:
>

Monday, February 20, 2012

Problem using Datareader Hasrow method

Edited by SomeNewKid. Please post code between<code> and</code> tags.



I do not know what is the problem. Any time I use Hasrow method I get the following error
"Compiler Error Message: BC30456: 'HasRows' is not a member of 'System.Data.SqlClient.SqlDataReader'.

Source Error:

Line 126: DRStudent = comm.executereader()
Line 127:
Line 128: if DRStudent.HasRows then
Line 129: blstudentexist = true
Line 130: else

On the top of my page I included:

<%@. import Namespace="System" %>
<%@. import Namespace="System.Data" %>
<%@. import Namespace="System.Data.SqlClient" %>

I do not know whether I need to include another import namespace...

This is the part of the code:

 Conn.open()
comm.connection = conn

'Verify whether the student exists
Query = " select * from tbl_student where Int_studentID = " & intSId
Comm = New SQLCommand(Query,Conn)
DRStudent = comm.executereader()

if DRStudent.HasRows then
blstudentexist = true
else
blstudentexist = false
end if
DRStudent.close()

I just making a simple select and trying to know whether it has any result.

Thanks,Are you using the 1.1 version of the .NET framework? This was not supported in 1.0.|||I am using 1.1 .Net framework. How can I know whether the select query result has any record?

Thanks,|||I have no idea why you cannot use that property. It really is supported in 1.1.

There is no other way to do a non-destructive read of a DataReader (you read the row, you use it - it is a one-way firehose sort of thing).|||I am using Web Matrix and MSDE. Does this have anything to do with my problem?
Thanks,|||No. That is a property of an object in the SqlClient provider. Can you check to see if perhasp .NET version 1.0 is installed and being used instead of version 1.1?|||I think I got both. How can I check which is being used?
Thanks,|||I do not know web matrix well enough to help...|||You might find something useful in this postHOWTO: Target .NET Framework v1.1 with Web Matrix v0.6 (happened to see this in the Forum Statistics and thought you might be able to apply it to your situation)

Terri