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

Friday, March 23, 2012

R

Hi,

I have a bit of code written in class ASP that connects to a database with Command.Execute. It works fine with SQL 2000 but after an upgrade to SQL 2005 causes the asp page to hang while w3wp runs at at 100%

I'm running SQL 2005 SP1 on the same machine as IIS. I can't see anything in the event log or the SQL logs that would explain this (no errors in either). SQL profiler shows the stored procedure is called.

The code is below. Does anyone know of anything that might be causing this. I've spent two days so far trying to find a cause. The ODBC connection SDB1 is using SQL Native Client.

MyConn.Open "DSN=SDB1;Initial Catalog=database","username","password"

Set MyCommand.ActiveConnection=MyConn
MyCommand.CommandType = adCmdStoredProc
MyCommand.CommandText = "[owner].[procname]"
Set MyParam=MyCommand.CreateParameter("in_ip",adVarChar,adParamInput,10)
MyCommand.Parameters.Append MyParam
Set MyResult=MyCommand.CreateParameter("ip_country",adVarChar,adParamOutput,50)
MyCommand.Parameters.Append MyResult

MyCommand.Execute

Can anyone shed any light on this?

For anybody elses reference, I have found the cause of this.

The database user had connect permission but nothing else. This meant the user could connect to the database but not select/update or delete. Giving it the necessary rights solved the problem.

However, why this was causing IIS to run at 100% is still a mystery.

Regards,

Mark.

sql

Wednesday, March 21, 2012

QUOTENAME Problem

I have following four cases


Code Snippet

1) select QUOTENAME (QUOTENAME ('ABCD', ''''),'''' )
Output: '''ABCD'''

Code Snippet

2) select QUOTENAME (QUOTENAME ('ABCD', ''''),']' )
Output: ['ABCD']

Code Snippet

3) select QUOTENAME (QUOTENAME ('ABCD', ''''),'"' )
Output: "'ABCD'"

Code Snippet

4) select QUOTENAME (QUOTENAME ('ABCD', '"'),'"' )
Output: """ABCD"""

Now my questions is second & three outputs are fine, but what happen to the first & forth one. I want single quote twice around string(in first case) and double quote twice around string(in forth case) but it gives me three single/double quotes, WHY ?

Gurpreet S. Gill

There was a recent post here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1537605&SiteID=1

In which I noted this behavior in Louis Davidson's example. This behavior also appears in books online so it is intended and you will need to account for it in your coding.

|||

Sorry, but I can not see what your concern is. Let me try to explain 1 and 4.

1 - select QUOTENAME (QUOTENAME ('ABCD', ''''),'''' )

The first call to the function will produce 'ABCD', correct?. Ther second call has to wrap the string 'ABCD' between aposthopes (including the existing aposthropes), so in order to wrap an aposthrope between apostropes you have to double the inner apostrophe. The result of the second call will be '''ABCD''', where the inner apostrophes were double. Let us put some spaces to differentiate them.

' ''ABCD'' '

2 - select QUOTENAME (QUOTENAME ('ABCD', '"'),'"' )

The same as in number 1, but this time both wrap will be between the double qoute ("). The inner double quote should be double and wrap them between double quote.

" ""ABCD"" "

We need to scape the character inside the string and we do it doubling the character being used, in those cases apostrophe and double quote. Let us see what happend if we decide to do the same with ']'.

select quotename(quotename('ABCD', ']'), ']')

Result:

[[ABCD]]]

The behavior with ']' is different compare with apostrophe or double quote, just the most right is doubled.

Hope my english does not get you dizzy.

AMB

Tuesday, March 20, 2012

Quickest method of updating a Table

I have a DataSet which I am holding in .NET and I would like to know the quickest way to get the DataSet in to a Table on SQL Server?

Any sample code would be great.

How many tables you have in dataset?

Fastest and easiest way to do it is probably using Data Adapter.

Thanks

|||Only one table, with over 1,000,000 records|||

And How you generate this data in your DataSet it is loaded from somewhere?

Fastest way will be to save it to file and next import to SQL using SSIS package or bulk copy command.

You can also try DataAdapter but

Thanks

it|||

And How you generate this data in your DataSet it is loaded from somewhere?

Fastest way will be to save it to file and next import to SQL using SSIS package or bulk copy command.

You can also try DataAdapter but

Thanks

it is|||

And How you generate this data in your DataSet it is loaded from somewhere?

Fastest way will be to save it to file and next import to SQL using SSIS package or bulk copy command.

You can also try DataAdapter but it

Thanks

|||

Hi CopperMill,

I agree that you can use SSIS to import data. You can also use bcp utility to perform fast bulk copy.

The bcp utility bulk copies data between an instance of Microsoft SQL Server 2005 and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into data files. Except when used with the queryout option, the utility requires no knowledge of Transact-SQL. To import data into a table, you must either use a format file created for that table or understand the structure of the table and the types of data that are valid for its columns.


For more information, please check

http://msdn2.microsoft.com/en-us/library/ms162802.aspx

If the data you need to insert has to be stay in the DataSet, The only way I can see is to use a SqlDataAdapter

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and we will look into it again. Thanks!

Wednesday, March 7, 2012

Quick Question

Joined: Oct 2001
Wednesday, February 06, 2002 4:10 PM (NEW!)



ERROR: ODBC Error Code = 22001
(String data right truncation) [Microsoft][ODBC SQL Server Driver][SQL
Server]String or binary data would be truncated.

I am using CF5 with SQL server 2000.

I have a text field on my page, which have value with double quotes..say for example, FORUM''s instead of FORUM's .
whether this will create the above error ?

Another thing i want to ask is, some users are able to get my page, without any above error. but some are getting this error. is it a browser issue. ? bcoz one of the user who have IE5.x is not able to access the page, but another user with IE5.x is able to view without any error. I am confused.

Can someone put shed light ? Please advise me... :)

Thanks !Somewhere along the way you are truncating data, you could be passing to long a value into a stored procedure parameter, or retrieving a data field into a variable that is too small.

It may work on one person browser but not the other person's, not because of the browser but because of what the program does.

Example;

A stored procedure is passed in a UserID and returns a clients profile, Firstname, lastname, telephone,...etc. The stored procedure could be defined with @.UserID as CHAR(8).

Use 1 - UserID = 'SMITHA' works
Use 2 - UserID = 'TRAPNELLJ' fails, because value being passed in is length 9.

You are going to have to go through your code.