Showing posts with label odbc. Show all posts
Showing posts with label odbc. Show all posts

Friday, March 30, 2012

Problem with SQLBindParameter

I am developing an application, using ODBC, that needs to call a stored procedure in an SQL Server DBMS that has a mix of INPUT and INPUT_OUTPUT parameters. I have the code so that there aren't any errors returned from the function calls but I do not see the bound data change after the SQLExecute() function.

Code snippets follow.

CHAR szStatement[256];

CHAR szBuf[256];

SQLINTEGER irval = 0, filenum = 808042, DoNotCall = 0;
SQLVARCHAR vcPhoneNumber[PHONE_LEN];
SQLVARCHAR vcInstanceCode[INSTANCE_LEN] = {0x20};
SQLVARCHAR vcReason[REASON_LEN] = {0x20};
SQLINTEGER rvalLen = 0, fileLen = 0, noCallLen = 10, phoneLen = SQL_NTS, instanceLen = SQL_NTS, reasonLen = SQL_NTS;

lstrcpy( szStatement, "exec ?= some_proc ?, ?, ?, ?, ?" );

sqlr = SQLPrepare( hStmt, szStatement, lstrlen( szStatement ) );
sqlr = SQLBindParameter( hStmt, 1, SQL_PARAM_OUTPUT, SQL_C_LONG, SQL_INTEGER, 10, 0, &irval, 0, &rvalLen );
sqlr = SQLBindParameter( hStmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 10, 0, &filenum, 0, &fileLen );
sqlr = SQLBindParameter( hStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 10, 0, vcPhoneNumber, 10, &phoneLen );
sqlr = SQLBindParameter( hStmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 50, 0, vcInstanceCode, 0, &instanceLen );
sqlr = SQLBindParameter( hStmt, 5, SQL_PARAM_INPUT_OUTPUT, SQL_C_LONG, SQL_INTEGER, 1, 0, &DoNotCall, 0, &noCallLen );
sqlr = SQLBindParameter( hStmt, 6, SQL_PARAM_INPUT_OUTPUT, SQL_C_CHAR, SQL_VARCHAR, 250, 0, vcReason, 0, &reasonLen );
sqlr = SQLExecute( hStmt );
if( sqlr == SQL_SUCCESS || sqlr == SQL_SUCCESS_WITH_INFO )

{
sprintf( szBuf, "The return value is %d", irval );
sprintf( szBuf, "The file number is %d", filenum );
sprintf( szBuf, "The phone number is %s", vcPhoneNumber );
sprintf( szBuf, "The instance code is %s", vcInstanceCode );
sprintf( szBuf, "The do not call value is %d", DoNotCall );
sprintf( szBuf, "The reason is %s", vcReason );
}

The problem is that in each of the function calls, the sqlr == SQL_SUCCESS but after the call to SQLExecute(), the data does not change for the output parameters. I can do something similar in other query tools that show the proper values but I am not getting the chanes in my bound variables. I tried adding a call to SQLParamData() but I was having a "Function sequence error" problem.

Any help would be very much appreciated. Thanks in advance.

Hi,

Here're a couple of ideas:

== The behavior of the output parameter may vary based on the actual stored proc, which you are trying to execute. To make sure your parameter description is precise, try using SQLProcedureColumns and examine the types.

== As per MSDN:

If the InputOutputType argument is SQL_PARAM_INPUT_OUTPUT or SQL_PARAM_OUTPUT, ParameterValuePtr points to a buffer in which the driver returns the output value. If the procedure returns one or more result sets, the *ParameterValuePtr buffer is not guaranteed to be set until all result sets/row counts have been processed. If the buffer is not set until processing is complete, the output parameters and return values are unavailable until SQLMoreResults returns SQL_NO_DATA. Calling SQLCloseCursor or SQLFreeStmt with an Option of SQL_CLOSE will cause these values to be discarded.

So what you could do is to fetch the results, call SQLMoreResults appropriately and see if the output parameter will be produced as expected. Also - don't forget the "SET NOCOUNT ON", you might get count tokens as separate resultsets.

HTH,

Jivko Dobrev - MSFT
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

At first I was having a problem with syntax errors and some other things that didn't make sense to me. I did some poking around and found that the signature I was given whas different from the signature that was defined in the data. I corrected this and was able to remove the errors. I tried calling SQLFetch() and was receiving an error of "Function sequense error." I can try again. The stored procedure does not return a result set. The return to me is throug a return code, the first parameter, and two in/out parameters, the last two.

I am connecting to someone else's system and they have defined the stored procedure and I don't have any control over how they've defined it.

The SQLExecute is returning SQL_SUCCESS_WITH_INFO and this message. The state is "01000" the native error is "0 The message is: [Microsoft][ODBC SQL Server Driver][SQL Server] The 01000 state is a generic message and that message sure looks generic. :)

I added a call to SQLFetch() after the SQLExecute() and the this is the result. The state is "HY010" the native error is "0 The message is: [Microsoft][ODBC SQL Server Driver]Function sequence error

I'm at a loss as to where to go now.

|||

Hi,

Would you be able to script the stored proc and the related tables/objects and post the script here? If it's not confidential or overly complicated, of course.

I have a suspicion about what you mentioned regarding the procedure not returning any rows. BTW - did you try the SQLMoreResults? Maybe you have multiple resultsets?

Thanks,

Jivko Dobrev - MSFT
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||

The stored procedure does not return a result set. I don't think SQLMoreResults() would help.

The body, from a snippet I've been given looks something like this:

/*IsOKToCall Procedure*/
CREATE PROCEDURE IsOKToCall
@.FileNumber int,
@.PhoneNumber char(10),
@.Instance varchar(50),
@.DoNotCall int OUTPUT,
@.DoNotCallReason varchar(255) OUTPUT
AS

SELECT @.Instance = ISNULL(@.Instance, 'master')

-- TODO implement this method to return a non-zero in @.DoNotCall if the account should not be contacted.

SELECT @.DoNotCall = 0
SELECT @.DoNotCallReason = ''
Return @.@.Error

GO

Note that this is not the actual procedure. The person that created it has some PRINT statements in the body to show some debug values and there is logic to return different results based on the value passed in the FileNumber parameter. If I change the first parameter to SQL_PARAMETER_RETURN, I get an error when trying to bind the column. The live procedure also defines the OUTPUT parameters as INPUT_OUTPUT.

|||

An update:

I installed SQL Express so I can see what is going on with both sides of the issue. Some of the error message I thought I had were messages from the "print ......" statements the developers put in thier stored procedures. If I call SQLFetch() after the statement execution, I always have an error of "Function Sequense Error" so I don't think that is why I am not getting values back.

Isn't SQLBindParameter() supposed to bind the parameter in the driver so that when the values are returned, they are also changed in the bound parameters? Is there something else I must do to the the correct values?

|||

Someone explain this one to me. The statement being called is "exec ?= IsOkToCall ?, ?, ?, ?, ?" as far and myself and the driver are concerned, there are six parameters. The first one is bound to an INTEGER to receive the @.@.Error value. the second is the ID to search for and is an input type. The third one is a char type and an input parameter. The fourth is a varchar input type. The fifth is an integer and is input_output type to get a result value for logic. And the sixth is a varchar input_output used to recieve the message string. After getting all of the messages from the driver, the sixth parameter is being updated with the value that was set for the fifth result code variable. Changing the parameter numbers to see if there is an off by one error does not fix it.

What should I be looking for for this issue?

|||

Robert,

Do not change the parameter numbers but you should try to call SQLMoreResults until you hit SQL_NO_DATA_FOUND and then see if the output parameters are updated or not. I believe print statements are treated as results and thus have to be flushed before getting to output parameters.

Thanks

Waseem

|||I found that out the hard way. It is after gathering all of the data that I am seeing the mixed up returns. The first parameter that is the return value from the procedure is never set and I still have the wrong value being updated with the integer value and it does not change even after I remove all of the print statements from the stored procedure.|||

Waseem Basheer - MSFT wrote:

Robert,

Do not change the parameter numbers but you should try to call SQLMoreResults until you hit SQL_NO_DATA_FOUND and then see if the output parameters are updated or not. I believe print statements are treated as results and thus have to be flushed before getting to output parameters.

Thanks

Waseem

I found this to be the case and was doing so. I also found where I was setting the destination to the address of a pointer to a character array rather than sending the pointer to the character array. I also found this whole thing to be increadably finicky and full of poorly/non documented quirks. I have the IN/OUT parmeters working but the return code fom a call of "exec ?= my_proc ?, ?, ?" still illudes me. I am still not getting the value for the ?= parameter but I don't think It is too important for me to get this value.

PROBLEM WITH SQL2000

hello..i have a really big problem with SQL2000 installation, i cant install it, some sql,odbc dll and other files left after i reinstalled OS without removing SQL,maybe 4 months ago and still have them in my pc, bought new HDD but they still exist in my pc :/ used full format of HDD but those files still left after all new installation of OS,i tryed to delete them but they appear again,deleted them from DOS but then i had to reinstall OS again coz windows dont started up.. what can i do ? plz help me some1 to solve this problem..i whant to install SQL2000 again but cant Sad((

hi keisa,

here's something to lighten up your day.

some versions of SQL server cannot be run on every OS

for example:

You cannot install a SQL server 2000 enterprise edition on windows Xp

because enterprise edition requires a windows server.

regards,

joey

|||

you never mentioned the OS. and sql server Edition and service pack.

please post back full info

Madhu

|||This sounds like a development or testing machine, if so why don't you simply refresh the complete installation from operating system to SQL Server.

Wednesday, March 28, 2012

Problem with SQL Server and odbc, please help me!

I have Visual Studio Dot.Net on Win XP and use the MSDE to access to Sql
Server.
This morning I've attempt to create a new ODBC DSN for Sql Server so
I've executed the wizard for a new System DSN by the ODBC administrator
of Windows. But when it attempts to connect to the server (the third
step of wizard) it give me somewhat like:
Connection impossible.
SQLState: '01000'
SQL Server error: 10049
SQLState: '08001'
SQL Server error: 17
I've tried to go forward with the manual configuration (uncheck the item
"Connect to an SQL Server for the default settings.." and press the Next
button), but at the end, when I press "Verify the data source", I have
no connection. So I've canceled the wizard.
The problem is that after that moment I have no connection with the server.
The console of MSDE indicate that the server is normally running, but I
can't connect to it neither by the Server Explorer of VS nor by osql.
I have always a message like:
[DBNETLIB][ConnectionOpen(Connect()).]Server non found or access denied.
Can someone help me?
Thanks
Tonio Tanzi
P.s. the messages of the server are probably a little different by the
ones indicate by me because I've translated them from the italian version.Tonio,
Is this a development server? If so try stopping the SQL Server service and
restarting it.
HTH
Jerry
"Tonio Tanzi" <vi.tan.gr@.inwind.it> wrote in message
news:m8c%e.3633$EZ.98724@.twister1.libero.it...
>I have Visual Studio Dot.Net on Win XP and use the MSDE to access to Sql
>Server.
> This morning I've attempt to create a new ODBC DSN for Sql Server so I've
> executed the wizard for a new System DSN by the ODBC administrator of
> Windows. But when it attempts to connect to the server (the third step of
> wizard) it give me somewhat like:
> Connection impossible.
> SQLState: '01000'
> SQL Server error: 10049
> SQLState: '08001'
> SQL Server error: 17
> I've tried to go forward with the manual configuration (uncheck the item
> "Connect to an SQL Server for the default settings.." and press the Next
> button), but at the end, when I press "Verify the data source", I have no
> connection. So I've canceled the wizard.
> The problem is that after that moment I have no connection with the
> server.
> The console of MSDE indicate that the server is normally running, but I
> can't connect to it neither by the Server Explorer of VS nor by osql.
> I have always a message like:
> [DBNETLIB][ConnectionOpen(Connect()).]Server non found or access denied.
>
> Can someone help me?
> Thanks
> Tonio Tanzi
> P.s. the messages of the server are probably a little different by the
> ones indicate by me because I've translated them from the italian version.|||Jerry Spivey ha scritto:
> Tonio,
> Is this a development server? If so try stopping the SQL Server service a
nd
> restarting it.
Yes. I've just stopped and restarted both Sql Server and computer many
times widhout any result.
Other suggest?
Bye
Tonio Tanzi

Friday, March 23, 2012

Problem with SP_Addlinkedserver when used in stored procedure

I wrote the following stored procedure. Note that SERVER_BK is an ODBC connection on the server that links to the remote server database.

--Creates the stored procedure that will be called in the Tablecounts script to send the comparison out to admins

if exists (select * from dbo.sysobjects where id = object_id(N'sp_compare_table_record_counts') and OBJECTPROPERTY(id, N'IsProcedure') = 1)

drop procedure sp_compare_table_record_counts

go

create proc sp_compare_table_record_counts as

-Creates the connection to the Remote Database. We need to make sure that the

-ODBC connections on each of the Production and Development Servers

-are named the same, so that we can use the same script and it will refer to the correct server

EXEC sp_addlinkedserver

@.server = 'SERVER_BK',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER_BK'

EXEC sp_addlinkedsrvlogin 'SERVER_BK', 'true'

set quoted_identifier off

select substring(remote_table.tablename,1,40) as Tablename, local_table.tablerowcount as L_SERVER,

remote_table.tablerowcount as R_SERVER,

case when remote_table.tablerowcount = local_table.tablerowcount then 'Counts Match'

else 'Counts Do Not Match'

end as Result_of_Compare

from OpenQuery([SERVER_BK], 'select * from tablecounts') remote_table, tablecounts local_table

where remote_table.tablename = local_table.tablename

order by Result_of_Compare, Tablename

-- table name on R_SERVER but not on L_SERVER

select substring(local_table.tablename,1,40) as 'Tables not on R_SERVER'

from tablecounts local_table where local_table.tablename not in (select * from OpenQuery([SERVER_BK], 'select tablename from tablecounts'))

-- table name on L_SERVER but not on R_SERVER

select substring(remote_table.tablename,1,40) as 'Tables not on L_SERVER'

from OpenQuery([SERVER_BK], 'select * from tablecounts') remote_table where remote_table.tablename not in (select tablename from tablecounts)

-Deletes the connection to the Remote Database to free up resources. This is just cleanup.

EXEC sp_dropserver 'SERVER_BK', 'droplogins'

I tested, and the stored procedure works OK when it is run as a New Query (i.e. I copy the guts and run it). When I execute the following, it fails:

exec msdb..sp_send_dbmail

@.profile_name = 'DB Mail Profile',

@.recipients = 'Recipient List',

@.query_no_truncate = 25,

@.query_result_separator = ' ',

@.subject = 'Record Counts',

@.query = 'exec db..sp_compare_table_record_counts', <--db is the appropriate db where the sp is

@.body_format = 'text'

Here is the error I get...any ideas would be greatly appreciated. I'm kind of new at this:

Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 476

Query execution failed: Msg 7399, Level 16, State 1, Server L_SERVER, Procedure sp_compare_table_record_counts, Line 28

The OLE DB provider "MSDASQL" for linked server "SERVER_BK" reported an error. The provider did not give any information about the error.

Msg 7303, Level 16, State 1, Server L_SERVER, Procedure sp_compare_table_record_counts, Line 28

Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "SERVER_BK".

Msg 0, Level 11, State 0, Line 0

A severe error occurred on the current command. The results, if any, should be discarded.

hope this link may help u :http://sqlserver2000.databases.aspfaq.com/how-do-i-prevent-linked-server-errors.html|||

Whoops, I forgot to mention that this is SQL 2005, SP1. I will check out the link though.

Any other ideas?

The other thing is that this only stops working when I turn this into a SP, when I run the first part (between but not including the create proc...as and the sp_send_dbmail) it seems to work fine.

I just can't turn this into a SP so that I can have DBMAIL execute it and mail the output.

|||

OK, I am going to change the problem a little bit, as I have made some progress. I decided to NOT make this a stored procedure, instead it is just one script now that does all of the work.

However, I still use this part of the code :

EXEC sp_addlinkedserver

@.server = 'SERVER_BK',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER_BK'

EXEC sp_addlinkedsrvlogin 'SERVER_BK', 'true'

select substring(local_table.tablename,1,40) as 'Tables not on R_SERVER'

from tablecounts local_table where local_table.tablename not in (select * from OpenQuery([SERVER_BK], 'select tablename from tablecounts'))

This works when I run it as myself, who happens to be an administrator in both locations, and the ODBC connection exists. The problem is when I schedule this as a job. I have a job that runs a tsql command, the job succeeds, but I get this in the log:

Line 59 Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "IFS_BK". OLE DB provider "MSDASQL" for linked server "IFS_BK" returned message "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).". OLE DB provider "MSDASQL" for linked server "IFS_BK" returned message "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.".

I know that this runs as the SQL Agent account, but I set the account as a db_datareader for that particular database on the other server. The SQL Agent account also is in the local administrators group of the OS on the remote system. Any ideas why this is failing?

|||

EXEC sp_addlinkedsrvlogin 'SERVER_BK', 'true'

when u give this statement the current users credentials are used to connect to the remote server also... check remote server have this user and same password

FROM BOL :

Determines the name of the login used to connect to the remote server. useself is varchar(8), with a default of TRUE.

A value of true specifies that logins use their own credentials to connect to rmtsrvname, with the rmtuser and rmtpassword arguments being ignored. false specifies that the rmtuser and rmtpassword arguments are used to connect to rmtsrvname for the specified locallogin. If rmtuser and rmtpassword are also set to NULL, no login or password is used to connect to the linked server

If remote server is having different user and password then u should use the below statement

EXEC master.dbo.sp_addlinkedsrvlogin @.rmtsrvname=N'Server2',@.useself=N'False',@.locallogin=NULL,@.rmtuser=N'SomeLoginInServer2',@.rmtpassword='Password'

Madhu

|||

Madhu,

Thank you, I think i'm on the right track now. I think I may have confused myself a bit though. The first lines of my script is this:

EXEC master.dbo.sp_addlinkedserver

@.server = 'SERVER2',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER2' --This is an ODBC connection that is setup in the system named SERVER. I was trying to do this to avoid having a username and password in a script.

EXEC master.dbo.sp_addlinkedsrvlogin

@.rmtsrvname=N'SERVER2',

@.useself=N'False',

@.locallogin=NULL,

@.rmtuser=N'USERNAME',

@.rmtpassword='PASSWORD'

My expectation is that I can now use a command like this further down in the same script:

OpenQuery([SERVER2], 'select * from TABLENAME')

and it would return everything in the TABLENAME table on the Other Server (server2). When I run the script, instead I get an error:

Msg 7202, Level 11, State 2, Line 67

Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

But it's not listing any errors creating the connection. What's the key i'm missing?

|||

Madhu,

Thank you, I think i'm on the right track now. I think I may have confused myself a bit though. The first lines of my script is this:

EXEC master.dbo.sp_addlinkedserver

@.server = 'SERVER2',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER2' --This is an ODBC connection that is setup in the system named SERVER. I was trying to do this to avoid having a username and password in a script.

EXEC master.dbo.sp_addlinkedsrvlogin

@.rmtsrvname=N'SERVER2',

@.useself=N'False',

@.locallogin=NULL,

@.rmtuser=N'USERNAME',

@.rmtpassword='PASSWORD'

My expectation is that I can now use a command like this further down in the same script:

OpenQuery([SERVER2], 'select * from TABLENAME')

and it would return everything in the TABLENAME table on the Other Server (server2). When I run the script, instead I get an error:

Msg 7202, Level 11, State 2, Line 67

Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

But it's not listing any errors creating the connection. What's the key i'm missing?

|||

Madhu,

Thank you, I think i'm on the right track now. I think I may have confused myself a bit though. The first lines of my script is this:

EXEC master.dbo.sp_addlinkedserver

@.server = 'SERVER2',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER2' --This is an ODBC connection that is setup in the system named SERVER. I was trying to do this to avoid having a username and password in a script.

EXEC master.dbo.sp_addlinkedsrvlogin

@.rmtsrvname=N'SERVER2',

@.useself=N'False',

@.locallogin=NULL,

@.rmtuser=N'USERNAME',

@.rmtpassword='PASSWORD'

My expectation is that I can now use a command like this further down in the same script:

OpenQuery([SERVER2], 'select * from TABLENAME')

and it would return everything in the TABLENAME table on the Other Server (server2). When I run the script, instead I get an error:

Msg 7202, Level 11, State 2, Line 67

Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

But it's not listing any errors creating the connection. What's the key i'm missing?

|||I did as you suggested, so this makes up the beginning of my script:

EXEC master.dbo.sp_addlinkedserver
@.server = 'SERVER2', --This is an ODBC connection that is setup on the machine.
@.srvproduct = '',
@.provider = 'MSDASQL',
@.datasrc = 'SERVER2'

EXEC master.dbo.sp_addlinkedsrvlogin
@.rmtsrvname=N'SERVER2',
@.useself=N'False',
@.locallogin=NULL,
@.rmtuser=N'USERNAME',
@.rmtpassword='PASSWORD'

Later in the script, I run this:
OpenQuery([SERVER2], 'select * from TABLENAME')

My expectation is that I would get all of the information from the TABLENAME table on SERVER2. Instead, I get this error message when the script runs:
Msg 7202, Level 11, State 2, Line 67
Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

I think i'm missing one important thing, but I can't figure out what it is.

My thought process is to have 1 script that:
1. Creates the connection to the other server, preferable through the System DSN so that I don't have to store a username/password in the code.
2. Access a table in the remote server that contains a bunch of rowcounts for that server
3. Compare the table from the remote rowcounts to the local rowcounts to make sure they match.

Maybe i'm just doing it the wrong way.
|||

At least you got me thinking...

I found the problem. I created the connection, but forgot to put "GO" to create the connection before I tried using it.

Now, it's working.

Thank you for your help.

Problem with SP_Addlinkedserver when used in stored procedure

I wrote the following stored procedure. Note that SERVER_BK is an ODBC connection on the server that links to the remote server database.

--Creates the stored procedure that will be called in the Tablecounts script to send the comparison out to admins

if exists (select * from dbo.sysobjects where id = object_id(N'sp_compare_table_record_counts') and OBJECTPROPERTY(id, N'IsProcedure') = 1)

drop procedure sp_compare_table_record_counts

go

create proc sp_compare_table_record_counts as

-Creates the connection to the Remote Database. We need to make sure that the

-ODBC connections on each of the Production and Development Servers

-are named the same, so that we can use the same script and it will refer to the correct server

EXEC sp_addlinkedserver

@.server = 'SERVER_BK',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER_BK'

EXEC sp_addlinkedsrvlogin 'SERVER_BK', 'true'

set quoted_identifier off

select substring(remote_table.tablename,1,40) as Tablename, local_table.tablerowcount as L_SERVER,

remote_table.tablerowcount as R_SERVER,

case when remote_table.tablerowcount = local_table.tablerowcount then 'Counts Match'

else 'Counts Do Not Match'

end as Result_of_Compare

from OpenQuery([SERVER_BK], 'select * from tablecounts') remote_table, tablecounts local_table

where remote_table.tablename = local_table.tablename

order by Result_of_Compare, Tablename

-- table name on R_SERVER but not on L_SERVER

select substring(local_table.tablename,1,40) as 'Tables not on R_SERVER'

from tablecounts local_table where local_table.tablename not in (select * from OpenQuery([SERVER_BK], 'select tablename from tablecounts'))

-- table name on L_SERVER but not on R_SERVER

select substring(remote_table.tablename,1,40) as 'Tables not on L_SERVER'

from OpenQuery([SERVER_BK], 'select * from tablecounts') remote_table where remote_table.tablename not in (select tablename from tablecounts)

-Deletes the connection to the Remote Database to free up resources. This is just cleanup.

EXEC sp_dropserver 'SERVER_BK', 'droplogins'

I tested, and the stored procedure works OK when it is run as a New Query (i.e. I copy the guts and run it). When I execute the following, it fails:

exec msdb..sp_send_dbmail

@.profile_name = 'DB Mail Profile',

@.recipients = 'Recipient List',

@.query_no_truncate = 25,

@.query_result_separator = ' ',

@.subject = 'Record Counts',

@.query = 'exec db..sp_compare_table_record_counts', <--db is the appropriate db where the sp is

@.body_format = 'text'

Here is the error I get...any ideas would be greatly appreciated. I'm kind of new at this:

Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 476

Query execution failed: Msg 7399, Level 16, State 1, Server L_SERVER, Procedure sp_compare_table_record_counts, Line 28

The OLE DB provider "MSDASQL" for linked server "SERVER_BK" reported an error. The provider did not give any information about the error.

Msg 7303, Level 16, State 1, Server L_SERVER, Procedure sp_compare_table_record_counts, Line 28

Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "SERVER_BK".

Msg 0, Level 11, State 0, Line 0

A severe error occurred on the current command. The results, if any, should be discarded.

hope this link may help u :http://sqlserver2000.databases.aspfaq.com/how-do-i-prevent-linked-server-errors.html|||

Whoops, I forgot to mention that this is SQL 2005, SP1. I will check out the link though.

Any other ideas?

The other thing is that this only stops working when I turn this into a SP, when I run the first part (between but not including the create proc...as and the sp_send_dbmail) it seems to work fine.

I just can't turn this into a SP so that I can have DBMAIL execute it and mail the output.

|||

OK, I am going to change the problem a little bit, as I have made some progress. I decided to NOT make this a stored procedure, instead it is just one script now that does all of the work.

However, I still use this part of the code :

EXEC sp_addlinkedserver

@.server = 'SERVER_BK',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER_BK'

EXEC sp_addlinkedsrvlogin 'SERVER_BK', 'true'

select substring(local_table.tablename,1,40) as 'Tables not on R_SERVER'

from tablecounts local_table where local_table.tablename not in (select * from OpenQuery([SERVER_BK], 'select tablename from tablecounts'))

This works when I run it as myself, who happens to be an administrator in both locations, and the ODBC connection exists. The problem is when I schedule this as a job. I have a job that runs a tsql command, the job succeeds, but I get this in the log:

Line 59 Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "IFS_BK". OLE DB provider "MSDASQL" for linked server "IFS_BK" returned message "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).". OLE DB provider "MSDASQL" for linked server "IFS_BK" returned message "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.".

I know that this runs as the SQL Agent account, but I set the account as a db_datareader for that particular database on the other server. The SQL Agent account also is in the local administrators group of the OS on the remote system. Any ideas why this is failing?

|||

EXEC sp_addlinkedsrvlogin 'SERVER_BK', 'true'

when u give this statement the current users credentials are used to connect to the remote server also... check remote server have this user and same password

FROM BOL :

Determines the name of the login used to connect to the remote server. useself is varchar(8), with a default of TRUE.

A value of true specifies that logins use their own credentials to connect to rmtsrvname, with the rmtuser and rmtpassword arguments being ignored. false specifies that the rmtuser and rmtpassword arguments are used to connect to rmtsrvname for the specified locallogin. If rmtuser and rmtpassword are also set to NULL, no login or password is used to connect to the linked server

If remote server is having different user and password then u should use the below statement

EXEC master.dbo.sp_addlinkedsrvlogin @.rmtsrvname=N'Server2',@.useself=N'False',@.locallogin=NULL,@.rmtuser=N'SomeLoginInServer2',@.rmtpassword='Password'

Madhu

|||

Madhu,

Thank you, I think i'm on the right track now. I think I may have confused myself a bit though. The first lines of my script is this:

EXEC master.dbo.sp_addlinkedserver

@.server = 'SERVER2',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER2' --This is an ODBC connection that is setup in the system named SERVER. I was trying to do this to avoid having a username and password in a script.

EXEC master.dbo.sp_addlinkedsrvlogin

@.rmtsrvname=N'SERVER2',

@.useself=N'False',

@.locallogin=NULL,

@.rmtuser=N'USERNAME',

@.rmtpassword='PASSWORD'

My expectation is that I can now use a command like this further down in the same script:

OpenQuery([SERVER2], 'select * from TABLENAME')

and it would return everything in the TABLENAME table on the Other Server (server2). When I run the script, instead I get an error:

Msg 7202, Level 11, State 2, Line 67

Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

But it's not listing any errors creating the connection. What's the key i'm missing?

|||

Madhu,

Thank you, I think i'm on the right track now. I think I may have confused myself a bit though. The first lines of my script is this:

EXEC master.dbo.sp_addlinkedserver

@.server = 'SERVER2',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER2' --This is an ODBC connection that is setup in the system named SERVER. I was trying to do this to avoid having a username and password in a script.

EXEC master.dbo.sp_addlinkedsrvlogin

@.rmtsrvname=N'SERVER2',

@.useself=N'False',

@.locallogin=NULL,

@.rmtuser=N'USERNAME',

@.rmtpassword='PASSWORD'

My expectation is that I can now use a command like this further down in the same script:

OpenQuery([SERVER2], 'select * from TABLENAME')

and it would return everything in the TABLENAME table on the Other Server (server2). When I run the script, instead I get an error:

Msg 7202, Level 11, State 2, Line 67

Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

But it's not listing any errors creating the connection. What's the key i'm missing?

|||

Madhu,

Thank you, I think i'm on the right track now. I think I may have confused myself a bit though. The first lines of my script is this:

EXEC master.dbo.sp_addlinkedserver

@.server = 'SERVER2',

@.srvproduct = '',

@.provider = 'MSDASQL',

@.datasrc = 'SERVER2' --This is an ODBC connection that is setup in the system named SERVER. I was trying to do this to avoid having a username and password in a script.

EXEC master.dbo.sp_addlinkedsrvlogin

@.rmtsrvname=N'SERVER2',

@.useself=N'False',

@.locallogin=NULL,

@.rmtuser=N'USERNAME',

@.rmtpassword='PASSWORD'

My expectation is that I can now use a command like this further down in the same script:

OpenQuery([SERVER2], 'select * from TABLENAME')

and it would return everything in the TABLENAME table on the Other Server (server2). When I run the script, instead I get an error:

Msg 7202, Level 11, State 2, Line 67

Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

But it's not listing any errors creating the connection. What's the key i'm missing?

|||I did as you suggested, so this makes up the beginning of my script:

EXEC master.dbo.sp_addlinkedserver
@.server = 'SERVER2', --This is an ODBC connection that is setup on the machine.
@.srvproduct = '',
@.provider = 'MSDASQL',
@.datasrc = 'SERVER2'

EXEC master.dbo.sp_addlinkedsrvlogin
@.rmtsrvname=N'SERVER2',
@.useself=N'False',
@.locallogin=NULL,
@.rmtuser=N'USERNAME',
@.rmtpassword='PASSWORD'

Later in the script, I run this:
OpenQuery([SERVER2], 'select * from TABLENAME')

My expectation is that I would get all of the information from the TABLENAME table on SERVER2. Instead, I get this error message when the script runs:
Msg 7202, Level 11, State 2, Line 67
Could not find server 'SERVER2' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

I think i'm missing one important thing, but I can't figure out what it is.

My thought process is to have 1 script that:
1. Creates the connection to the other server, preferable through the System DSN so that I don't have to store a username/password in the code.
2. Access a table in the remote server that contains a bunch of rowcounts for that server
3. Compare the table from the remote rowcounts to the local rowcounts to make sure they match.

Maybe i'm just doing it the wrong way.
|||

At least you got me thinking...

I found the problem. I created the connection, but forgot to put "GO" to create the connection before I tried using it.

Now, it's working.

Thank you for your help.

Monday, March 12, 2012

Problem with 'sa' user and password

Hello.
I have problem with connection to my SQL server 2000 through 'sa' user
without password.
On my windows XP with Access XP I created ODBC Source, user DSN source for
default user 'sa'. On SQL this user has not a password. Now, in Access, when
I try to open linked (from SQL Server) tables the dialog window appears and
system tells me to enter the password (which is empty). Then I must only
press Enter, and table is being opened. What should I do to avoid pressing
Enter, in other words, What should I do in order to get access to tables
without this appearing dialog window to enter the password?
Thank you very much for help.
PS. Without solution for this problem I can not run my batch jobs, and it is
very bad, and I'm getting nervous ;)
I am not sure that you can do this. The password, or in this case, the lack
of password, does not get stored in the DSN. So the dialog box has to open
so you cna supply it.
Rand
This posting is provided "as is" with no warranties and confers no rights.

Problem with 'sa' user and password

Hello.
I have problem with connection to my SQL server 2000 through 'sa' user
without password.
On my Windows XP with Access XP I created ODBC Source, user DSN source for
default user 'sa'. On SQL this user has not a password. Now, in Access, when
I try to open linked (from SQL Server) tables the dialog window appears and
system tells me to enter the password (which is empty). Then I must only
press Enter, and table is being opened. What should I do to avoid pressing
Enter, in other words, What should I do in order to get access to tables
without this appearing dialog window to enter the password?
Thank you very much for help.
PS. Without solution for this problem I can not run my batch jobs, and it is
very bad, and I'm getting nervous ;)I am not sure that you can do this. The password, or in this case, the lack
of password, does not get stored in the DSN. So the dialog box has to open
so you cna supply it.
Rand
This posting is provided "as is" with no warranties and confers no rights.

Problem with resto odbc sqlstate: 42000

I got this error when I do a manual restore:
"odbc sqlstate: 42000"
Please help,
CulamYour database is running a shadow copy.
Delete the database, and the real copy will then show back up in the list.
"culam" <culam@.discussions.microsoft.com> wrote in message
news:442BB61D-C504-4FA2-B097-1AF2A34403B4@.microsoft.com...
> I got this error when I do a manual restore:
> "odbc sqlstate: 42000"
> Please help,
> Culam

Friday, March 9, 2012

Problem with Reporting Service SQL 2000 and Sybase

Hi,
The connection to Sybase with OLEDB and ODBC have the same problem when the
query have parameter. The query below don´t execute:
select prod_cod,cod_empresa from estatistica.dbo.zomba
where vida = @.vida
OLEDB error: "An error occurred while executing the query. The given type
name was unrecognized"
versions used: 02.70.0016 and 02.70.0042 (provided by Sybase support)
ODBC error: "Error [HY000][DataDirect][ODBC Sybase wire protocol driver][SQL
Server] must declare variable @.vida"
versions used: 04.10.0049 (provided by Sybase support)
Someone have the same problem?
Thanks,
LandryI work extensively with Sybase. The issue you are seeing is that query
variables for ODBC have to be a ? (unnamed parameter). I suggest you stick
with the ODBC driver. I have had issues with OLEDB.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Landry" <landry@.dsai.com.br.NEWS> wrote in message
news:em6ndG7RFHA.688@.TK2MSFTNGP10.phx.gbl...
> Hi,
> The connection to Sybase with OLEDB and ODBC have the same problem when
> the
> query have parameter. The query below don´t execute:
> select prod_cod,cod_empresa from estatistica.dbo.zomba
> where vida = @.vida
> OLEDB error: "An error occurred while executing the query. The given type
> name was unrecognized"
> versions used: 02.70.0016 and 02.70.0042 (provided by Sybase support)
> ODBC error: "Error [HY000][DataDirect][ODBC Sybase wire protocol
> driver][SQL
> Server] must declare variable @.vida"
> versions used: 04.10.0049 (provided by Sybase support)
> Someone have the same problem?
> Thanks,
> Landry
>
>|||Hi,
Thanks.
I test ? with OLEDB and ODBC and have the same error!
select prod_cod,cod_empresa from estatistica.dbo.zomba
where vida = ?
I test Stored Procedures with parameters and have the same error.
Landry
"Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> escreveu na mensagem
news:u%23sw%23m7RFHA.3704@.TK2MSFTNGP12.phx.gbl...
>I work extensively with Sybase. The issue you are seeing is that query
>variables for ODBC have to be a ? (unnamed parameter). I suggest you stick
>with the ODBC driver. I have had issues with OLEDB.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Landry" <landry@.dsai.com.br.NEWS> wrote in message
> news:em6ndG7RFHA.688@.TK2MSFTNGP10.phx.gbl...
>> Hi,
>> The connection to Sybase with OLEDB and ODBC have the same problem when
>> the
>> query have parameter. The query below don´t execute:
>> select prod_cod,cod_empresa from estatistica.dbo.zomba
>> where vida = @.vida
>> OLEDB error: "An error occurred while executing the query. The given
>> type
>> name was unrecognized"
>> versions used: 02.70.0016 and 02.70.0042 (provided by Sybase support)
>> ODBC error: "Error [HY000][DataDirect][ODBC Sybase wire protocol
>> driver][SQL
>> Server] must declare variable @.vida"
>> versions used: 04.10.0049 (provided by Sybase support)
>> Someone have the same problem?
>> Thanks,
>> Landry
>>
>>
>|||The best thing to do is as you are doing, first get a query and then move on
to stored procedures. That is the data type of vida?
Also, when are you getting this error? From the data tab clicking on the ! ?
Or from the preview?
Let's concentrate on ODBC. What error do you get with ODBC (it can't be the
same as before because at that point you had this error: must declare
variable @.vida).
I do all my queries from the generic query window. Try that (the button is
to the right of the ... to switch to generic query designer).
Also, what version of Sysbase. I am using 12.5.2 client and have used that
against both an 11.x (I don't remember the exact version) and 12.5.1
servers.
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Landry" <landry@.dsai.com.br.NEWS> wrote in message
news:e4V1j7BSFHA.1348@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Thanks.
> I test ? with OLEDB and ODBC and have the same error!
> select prod_cod,cod_empresa from estatistica.dbo.zomba
> where vida = ?
> I test Stored Procedures with parameters and have the same error.
> Landry
> "Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> escreveu na mensagem
> news:u%23sw%23m7RFHA.3704@.TK2MSFTNGP12.phx.gbl...
>>I work extensively with Sybase. The issue you are seeing is that query
>>variables for ODBC have to be a ? (unnamed parameter). I suggest you stick
>>with the ODBC driver. I have had issues with OLEDB.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Landry" <landry@.dsai.com.br.NEWS> wrote in message
>> news:em6ndG7RFHA.688@.TK2MSFTNGP10.phx.gbl...
>> Hi,
>> The connection to Sybase with OLEDB and ODBC have the same problem when
>> the
>> query have parameter. The query below don´t execute:
>> select prod_cod,cod_empresa from estatistica.dbo.zomba
>> where vida = @.vida
>> OLEDB error: "An error occurred while executing the query. The given
>> type
>> name was unrecognized"
>> versions used: 02.70.0016 and 02.70.0042 (provided by Sybase support)
>> ODBC error: "Error [HY000][DataDirect][ODBC Sybase wire protocol
>> driver][SQL
>> Server] must declare variable @.vida"
>> versions used: 04.10.0049 (provided by Sybase support)
>> Someone have the same problem?
>> Thanks,
>> Landry
>>
>>
>>
>|||Hi Bruce,
Thanks, the problem is ODBC version, now work fine with cliente version
12.5.3, the most recent.
The Sybase suport will analyze the OLEDB to correct the error.
Thanks,
Landry
"Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> escreveu na mensagem
news:urhgPMCSFHA.3336@.TK2MSFTNGP09.phx.gbl...
> The best thing to do is as you are doing, first get a query and then move
> on to stored procedures. That is the data type of vida?
> Also, when are you getting this error? From the data tab clicking on the !
> ? Or from the preview?
> Let's concentrate on ODBC. What error do you get with ODBC (it can't be
> the same as before because at that point you had this error: must declare
> variable @.vida).
> I do all my queries from the generic query window. Try that (the button is
> to the right of the ... to switch to generic query designer).
> Also, what version of Sysbase. I am using 12.5.2 client and have used that
> against both an 11.x (I don't remember the exact version) and 12.5.1
> servers.
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Landry" <landry@.dsai.com.br.NEWS> wrote in message
> news:e4V1j7BSFHA.1348@.TK2MSFTNGP15.phx.gbl...
>> Hi,
>> Thanks.
>> I test ? with OLEDB and ODBC and have the same error!
>> select prod_cod,cod_empresa from estatistica.dbo.zomba
>> where vida = ?
>> I test Stored Procedures with parameters and have the same error.
>> Landry
>> "Bruce L-C [MVP]" <bruce_lcNOSPAM@.hotmail.com> escreveu na mensagem
>> news:u%23sw%23m7RFHA.3704@.TK2MSFTNGP12.phx.gbl...
>>I work extensively with Sybase. The issue you are seeing is that query
>>variables for ODBC have to be a ? (unnamed parameter). I suggest you
>>stick with the ODBC driver. I have had issues with OLEDB.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Landry" <landry@.dsai.com.br.NEWS> wrote in message
>> news:em6ndG7RFHA.688@.TK2MSFTNGP10.phx.gbl...
>> Hi,
>> The connection to Sybase with OLEDB and ODBC have the same problem when
>> the
>> query have parameter. The query below don´t execute:
>> select prod_cod,cod_empresa from estatistica.dbo.zomba
>> where vida = @.vida
>> OLEDB error: "An error occurred while executing the query. The given
>> type
>> name was unrecognized"
>> versions used: 02.70.0016 and 02.70.0042 (provided by Sybase support)
>> ODBC error: "Error [HY000][DataDirect][ODBC Sybase wire protocol
>> driver][SQL
>> Server] must declare variable @.vida"
>> versions used: 04.10.0049 (provided by Sybase support)
>> Someone have the same problem?
>> Thanks,
>> Landry
>>
>>
>>
>>
>

Wednesday, March 7, 2012

Problem with reading in packet mode

Hi,
I'm using the following environment:
OS: Windows XP professional
SQL Server ODBC driver version: 2000.85.1117.00
RDBMS: SQL Server 2000
I have a question about reading a table in packet mode
using ODBC (i.e. using SQL_ROWSET_SIZE statement option).
I performed the following scenario:
1. I created a table with one int column (e.g. CREATE TABLE [TREAD] (Field1
int NULL))
2. I populated this table with 1 million records
3. I wrote a small basic ODBC application (console application using
Microsoft Visual C++ 6) to simply
read these records with minimum overhead (i.e. no other expensive
operations, no extensive console text output, etc.),
see attached sample.
4. Within this ODBC application, I'm reading/fetching all the records using
SQL_ROWSET_SIZE with value 10 (i.e. packet mode).
The problem is the following:
The relevant code for setting the packet mode is as follows, see attached
sample:
//...
//rc = SQLSetStmtOption(StmtHandle, SQL_ROWSET_SIZE, 10);
rc = SQLExecDirect(StmtHandle, SQLStmt, SQL_NTS);
rc = SQLSetStmtOption(StmtHandle, SQL_ROWSET_SIZE, 10);
//...
If SQLSetStmtOption() is called after SQLExecDirect(), the reading is very
fast, i.e. 1 sec.
If SQLSetStmtOption() is called before SQLExecDirect(), the reading is very
slow, i.e. 49 secs.
My question: which is the right call order ? So far, from the ODBC official
docs, I understand that
SQLSetStmtOption() can be called before and/or after SQLExecDirect() and, at
least in this case, it
shouldn't make any difference. I don't try to use different rowset/packet
sizes during reading, I just
try to read all records with a certain packet size (e.g. 10) from the very
beginning to the end.
Thanks for your help,
Ovidiu
begin 666 TestReadPacket.cpp
M+R]T97-T(')E860@.<&%C:V5T#0H-"B-I;F-L=61E(#QW:6YD;W=S+F@.^#0HC
M:6YC;'5D92 \<W%L+F@.^#0HC:6YC;'5D92 \<W%L97AT+F@.^#0HC:6YC;'5D
M92 \:6]S=')E86TN:#X-"B-I;F-L=61E(#QS=')I;F<N:#X-"B-I;F-L=61E
M(#QM871H+F@.^#0HC:6YC;'5D92 \=&EM92YH/@.T*#0IC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0H)
M>PT*"0ER8R ](%-13$5R<F]R*$5N=DAA;F1L92P@.0V]N2&%N9&QE+" P+"!S
M=')3=&%T92P@.)G-Q;$1B0V]D92P@.<W1R1&)-97-S86=E+"!344Q?34%87TU%
M4U-!1T5?3$5.1U1(("T@.,2 L("9C8F5R<F]R;7-G("D[#0H)"0T*"0EI9B H
M(')C(#T](%-13%]354-#15-3("D-"@.D)>PT*"0D)<W1R8V%T*'-T<BP@.*&-O
M;G-T(&-H87(J*2!S=')3=&%T92D[#0H)"0ES=')C870H<W1R+" B(" B*3L-
M"@.D)"7-T<F-A="AS='(L("AC;VYS="!C:&%R*BD@.<W1R1&)-97-S86=E*3L-
M"@.D)?0T*"7T@.=VAI;&4H(')C(#T](%-13%]354-#15-3("D[#0H)#0H)8V]U
M=" \/" B17)R;W(@.;65S<V%G93H@.(B \/"!E;F1L.PT*"6-O=70@./#P@.<W1R
M(#P\(&5N9&P[#0I]#0H-"G9O:60@.;6%I;B@.I#0I[#0H)=&EM95]T('-T87)T
M.PT*"71I;65?="!E;F0[#0H-"@.ET:6UE*"9S=&%R="D[#0H-"B @.("!2151#
M3T1%("!R8R ](%-13%]354-#15-3.PT*(" @.(%-13$-(05(@.($1"3F%M95LR
M,%T@./2 B4U%,,C P,"([#0H@.(" @.4U%,0TA!4B @.4U%,4W1M=%LR-35=.PT*
M#0H@.(" @.3T1"0U]#;&%S<R @.17AA;7!L93L-"@.T*(" @.(&EF("A%>&%M<&QE
M+D-O;DAA;F1L92 A/2!.54Q,*0T*(" @.('L-"B @.(" @.(" @.<F,@./2!344Q#
M;VYN96-T*$5X86UP;&4N0V]N2&%N9&QE+"!$0DYA;64L(%-13%].5%,L( T*
M(" @.(" @.(" @.(" @.(" @.(" H4U%,0TA!4B J*2 B<FYD9&(U(BP@.4U%,7TY4
M4RP@.*%-13$-(05(@.*BD@.(F]V:61I=2(L(%-13%].5%,I.PT*#0H@.(" @.(" @.
M(')C(#T@.4U%,06QL;V-3=&UT*$5X86UP;&4N0V]N2&%N9&QE+" F17AA;7!L
M92Y3=&UT2&%N9&QE*3L-"@.T*(" @.(" @.("!I9B H<F,@./3T@.4U%,7U-50T-%
M4U,@.?'P@.<F,@./3T@.4U%,7U-50T-%4U-?5TE42%])3D9/*0T*(" @.(" @.("![
M#0H@.(" @.(" @.(" @.("!S=')C<'DH*&-H87(@.*BD@.4U%,4W1M="P@.(E-%3$5#
M5"!&:65L9#$@.1E)/32!44D5!1"(I.PT*#0H)"0ER8R ](#HZ4U%,4V5T4W1M
M=$]P=&EO;BA%>&%M<&QE+E-T;71(86YD;&4L(%-13%]23U=3151?4TE:12P@.
M,3 I.PD-"@.D)"7)C(#T@.4U%,17AE8T1I<F5C="A%>&%M<&QE+E-T;71(86YD
M;&4L(%-13%-T;70L(%-13%].5%,I.PT*"0D)+R]R8R ](#HZ4U%,4V5T4W1M
M=$]P=&EO;BA%>&%M<&QE+E-T;71(86YD;&4L(%-13%]23U=3151?4TE:12P@.
M,3 I.PD-"@.T*(" @.(" @.(" @.(" @.:68@.*')C(#T](%-13%]354-#15-3*0T*
M(" @.(" @.(" @.(" @.(" @.($5X86UP;&4N4VAO=U)E<W5L=',H*3L-"@.T*(" @.
M(" @.(" @.(" @.:68@.*$5X86UP;&4N4W1M=$AA;F1L92 A/2!.54Q,*0T*(" @.
M(" @.(" @.(" @.(" @.(')C(#T@.4U%,1G)E95-T;70H17AA;7!L92Y3=&UT2&%N
M9&QE+"!344Q?1%)/4"D[#0H@.(" @.(" @.('T-"@.D)96QS90T*"0E[#0H)"0E%
M>&%M<&QE+E!R:6YT17)R;W(H*3L-"@.D)?0T*#0H@.(" @.(" @.(')C(#T@.4U%,
M1&ES8V]N;F5C="A%>&%M<&QE+D-O;DAA;F1L92D[#0H@.(" @.?0T*#0H)=&EM
M92@.F96YD*3L-"@.T*"6-O=70@./#P@.(G1I;64@.96QA<'-E9" ]("(@./#P@.96YD
F("T@.<W1A<G0@./#P@.(B!S96-O;F1S(B \/"!E;F1L.PT*?0T*#0H`
`
end
Hi Ovidiu,
First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you call SQLSetStmtOption() before
SQLExecDirect() the performance is quite poor. If there is any
misunderstanding, please feel free to let me know.
Yes, as you know, the SQLSetStmtOption can be called before/after
SQLExecDirect. However, from ODBC 3.x SQLSetStmtOption is deprecated. It
has been replaced by SQLSetStmtAttr. So I suggest you try to use
SQLSetStmtAttr to see if performance goes better. Please check the
following link for more information.
http://msdn.microsoft.com/library/de...us/odbc/htm/od
bcsqlsetstmtoption.asp
If that still doens't work, please feel free to reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
|||Hi Kevin,
Thank you for your quick reply.
I did try using the new functions: SQLSetStmtAttr instead of
SQLSetStmtOption and SQLFetchScroll instead of SQLExtendedFetch
respectively,
and still the problem is absolutely the same.
I attached a revised sample.
Thanks,
Ovidiu
"Kevin Yu [MSFT]" <v-kevy@.online.microsoft.com> wrote in message
news:byomeErhFHA.940@.TK2MSFTNGXA01.phx.gbl...
> Hi Ovidiu,
> First of all, I would like to confirm my understanding of your issue. From
> your description, I understand that when you call SQLSetStmtOption()
> before
> SQLExecDirect() the performance is quite poor. If there is any
> misunderstanding, please feel free to let me know.
> Yes, as you know, the SQLSetStmtOption can be called before/after
> SQLExecDirect. However, from ODBC 3.x SQLSetStmtOption is deprecated. It
> has been replaced by SQLSetStmtAttr. So I suggest you try to use
> SQLSetStmtAttr to see if performance goes better. Please check the
> following link for more information.
> http://msdn.microsoft.com/library/de...us/odbc/htm/od
> bcsqlsetstmtoption.asp
> If that still doens't work, please feel free to reply to the post.
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
begin 666 TestReadPacketNew.cpp
M+R]T97-T(')E860@.<&%C:V5T#0H-"B-I;F-L=61E(#QW:6YD;W=S+F@.^#0HC
M:6YC;'5D92 \<W%L+F@.^#0HC:6YC;'5D92 \<W%L97AT+F@.^#0HC:6YC;'5D
M92 \:6]S=')E86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344Q21515
M4DX@.(')C.PT*"5-13$-(05()"0ES=')3=&%T95M344Q?4U%,4U1!5$5?4TE:
M12 K(#%=.PT*"5-13$E.5$5'15()"7-Q;$1B0V]D92 )"3T@.,#L-"@.E344Q#
M2$%2"0D)<W1R1&)-97-S86=E6U-13%]-05A?34534T%'15],14Y'5$A=.PT*
M"5-13%--04Q,24Y4"0EC8F5R<F]R;7-G"0D](# [#0H)8VAA<@.D)"7-T<ELQ
M,#!=.PT*"7-T<F-P>2AS='(L("(B*3L-"@.D-"@.ED;PT*"7L-"@.D)<F,@./2!3
M44Q%<G)O<BA%;G9(86YD;&4L($-O;DAA;F1L92P@.,"P@.<W1R4W1A=&4L("9S
M<6Q$8D-O9&4L('-T<D1B365S<V%G92P@.4U%,7TU!6%]-15-304=%7TQ%3D=4
M2" M(#$@.+" F8V)E<G)O<FUS9R I.PT*"0D-"@.D):68@.*"!R8R ]/2!344Q?
M4U5#0T534R I#0H)"7L-"@.D)"7-T<F-A="AS='(L("AC;VYS="!C:&%R*BD@.
M<W1R4W1A=&4I.PT*"0D)<W1R8V%T*'-T<BP@.(B @.(BD[#0H)"0ES=')C870H
M<W1R+" H8V]N<W0@.8VAA<BHI('-T<D1B365S<V%G92D[#0H)"7T-"@.E]('=H
M:6QE*"!R8R ]/2!344Q?4U5#0T534R I.PT*"0T*"6-O=70@./#P@.(D5R<F]R
M(&UE<W-A9V4Z("(@./#P@.96YD;#L-"@.EC;W5T(#P\('-T<B \/"!E;F1L.PT*
M?0T*#0IV;VED(&UA:6XH*0T*>PT*"71I;65?="!S=&%R=#L-"@.ET:6UE7W0@.
M96YD.PT*#0H)=&EM92@.F<W1A<G0I.PT*#0H@.(" @.4D540T]$12 @.<F,@./2!3
M44Q?4U5#0T534SL-"B @.("!344Q#2$%2("!$0DYA;65;,C!=(#T@.(E-13#(P
M,# B.PT*(" @.(%-13$-(05(@.(%-13%-T;71;,C4U73L-"@.E344Q524Y414=%
M4B @.07)R87E3:7IE(#T@.,3 [#0H-"B @.("!/1$)#7T-L87-S("!%>&%M<&QE
M.PT*#0H@.(" @.:68@.*$5X86UP;&4N0V]N2&%N9&QE("$]($Y53$PI#0H@.(" @.
M>PT*(" @.(" @.("!R8R ](%-13$-O;FYE8W0H17AA;7!L92Y#;VY(86YD;&4L
M($1"3F%M92P@.4U%,7TY44RP@.#0H@.(" @.(" @.(" @.(" @.(" @.("A344Q#2$%2
M("HI(")R;F1D8C4B+"!344Q?3E13+" H4U%,0TA!4B J*2 B;W9I9&EU(BP@.
M4U%,7TY44RD[#0H-"B @.(" @.(" @.<F,@./2!344Q!;&QO8U-T;70H17AA;7!L
M92Y#;VY(86YD;&4L("9%>&%M<&QE+E-T;71(86YD;&4I.PT*#0H@.(" @.(" @.
M(&EF("AR8R ]/2!344Q?4U5#0T534R!\?"!R8R ]/2!344Q?4U5#0T534U]7
M251(7TE.1D\I#0H@.(" @.(" @.('L-"B @.(" @.(" @.(" @.('-T<F-P>2@.H8VAA
M<B J*2!344Q3=&UT+" B4T5,14-4($9I96QD,2!&4D]-(%1214%$(BD[#0H-
M"@.D)"7)C(#T@.4U%,4V5T4W1M=$%T='(H17AA;7!L92Y3=&UT2 &%N9&QE+"!3
M44Q?05144E]23U=?05)205E?4TE:12P@.*%-13%!/24Y415(I($%R<F%Y4VEZ
M92P@.,"D[#0H-"@.D)"2\O<F,@./2 Z.E-13%-E=%-T;71/<'1I;VXH17AA;7!L
M92Y3=&UT2&%N9&QE+"!344Q?4D]74T547U-)6D4L(#$P*3L)#0H)"0ER8R ]
M(%-13$5X96-$:7)E8W0H17AA;7!L92Y3=&UT2&%N9&QE+"!344Q3=&UT+"!3
M44Q?3E13*3L-"@.D)"2\O<F,@./2 Z.E-13%-E=%-T;71/<'1I;VXH17AA;7!L
M92Y3=&UT2&%N9&QE+"!344Q?4D]74T547U-)6D4L(#$P*3L)#0H-"@.D)"2\O
M<F,@./2!344Q39713=&UT071T<BA%>&%M<&QE+E-T;71(86YD;&4L(%-13%]!
M5%127U)/5U]!4E)!65]325I%+" H4U%,4$])3E1%4BD@.07)R87E3:7IE+" P
M*3L-"@.T*(" @.(" @.(" @.(" @.:68@.*')C(#T](%-13%]354-#15-3*0T*(" @.
M(" @.(" @.(" @.(" @.($5X86UP;&4N4VAO=U)E<W5L=',H*3L-"@.T*(" @.(" @.
M(" @.(" @.:68@.*$5X86UP;&4N4W1M=$AA;F1L92 A/2!.54Q,*0T*(" @.(" @.
M(" @.(" @.(" @.(')C(#T@.4U%,1G)E95-T;70H17AA;7!L92Y3=&UT2&%N9&QE
M+"!344Q?1%)/4"D[#0H@.(" @.(" @.('T-"@.D)96QS90T*"0E[#0H)"0E%>&%M
M<&QE+E!R:6YT17)R;W(H*3L-"@.D)?0T*#0H@.(" @.(" @.(')C(#T@.4U%,1&ES
M8V]N;F5C="A%>&%M<&QE+D-O;DAA;F1L92D[#0H@.(" @.?0T*#0H)=&EM92@.F
M96YD*3L-"@.T*"6-O=70@./#P@.(G1I;64@.96QA<'-E9" ]("(@./#P@.96YD("T@.
C<W1A<G0@./#P@.(B!S96-O;F1S(B \/"!E;F1L.PT*?0T*#0H`
`
end
|||Hi Ovidiu,
What is the version of MDAC on your machine? Please try to upgrade to the
latest version MDAC 2.8 sp1 from the following link to see if it can
resolved the problem.
http://www.microsoft.com/downloads/d...895-efc2-4f8e-
a9e0-3a1afbd5922e&DisplayLang=en
Also I suggest you try to set to a larger packet size (e.g. 512).
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
|||Hi Kevin,
Yes, I have the latest MDAC version: MDAC 2.8 SP1 on WINDOWS XP SP2.
It's true, the performance gets much better when we increase the packet size
(we already knew that), as follows:
- for packet size 512 I get aprox. 7 secs (compared to 49 secs)
- increasing packet size over 512 won't improve performance anymore
The bottom line is: even when using larger values for the packet size,
performance is still poor compared
to the case when SQLSetStmtOption is called after SQLExecDirect (7 secs vs.
1 sec). Why is that happening ?
So, increasing packet size is a good workaround but up to a point.
There is the following bussiness impact: the customers using our application
are asking questions about this (strange) behaviour. Is there any
Microsoft doc, release note, etc. that refers to it ?
Could this issue be escalated such that, at least, we could get an official
answer from Microsoft regarding this behaviour. This would prove at
least that we are not misusing the ODBC API in any way (this was our main
concern in the first place because, actually, the order of ODBC
calls causes this strange behaviour).
Your help is appreciated.
Regards,
Ovidiu
"Kevin Yu [MSFT]" <v-kevy@.online.microsoft.com> wrote in message
news:hYsGn42hFHA.944@.TK2MSFTNGXA01.phx.gbl...
> Hi Ovidiu,
> What is the version of MDAC on your machine? Please try to upgrade to the
> latest version MDAC 2.8 sp1 from the following link to see if it can
> resolved the problem.
> http://www.microsoft.com/downloads/d...895-efc2-4f8e-
> a9e0-3a1afbd5922e&DisplayLang=en
> Also I suggest you try to set to a larger packet size (e.g. 512).
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
|||Hi Ovidiu,
Here, I suggest you try to use 4096 as the packet size to see if there is
any performance increment.. To get an official answer from Microsoft, you
need to contact PSS for professional support. You can find the contact
information from the following link:
http://support.microsoft.com/common/...gp;en-us;offer
prophone
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
|||Hi Kevin,
As I already specified in my previous reply, increasing packet size over a
certain limit won't improve performance anymore.
Thanks for your help. I will try to escalate this issue through PSS.
Regards,
Ovidiu
"Kevin Yu [MSFT]" <v-kevy@.online.microsoft.com> wrote in message
news:clVPgQDiFHA.3120@.TK2MSFTNGXA01.phx.gbl...
> Hi Ovidiu,
> Here, I suggest you try to use 4096 as the packet size to see if there is
> any performance increment.. To get an official answer from Microsoft, you
> need to contact PSS for professional support. You can find the contact
> information from the following link:
> http://support.microsoft.com/common/...gp;en-us;offer
> prophone
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
|||Hi Ovidiu,
Sorry that I could not provide further assistance on this issue. Good luck!
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."