Showing posts with label executing. Show all posts
Showing posts with label executing. Show all posts

Friday, March 30, 2012

problem with Log

Hello,

Could anybody let me know why is this happening while executing a stored procedure through asp.net

Log Entry string is too long. A string written to the event log cannot exceed 32766 characters.

general

The message sounds like you tried to write a very large string to you system event log.
Possibly as a result of throwing an exception when trying to call the stored proc.

Do you have an Exception logging mechanism in place that is configured to put exception messages into your system Event Log?

Can you step into the code to see any possible exception when you make the stored proc call, or turn off exception handling/logging for this call and let the exception go to the page.

sql

Friday, March 23, 2012

Problem with INSERT INTO Temp Table on SQL 2000 using Linked Server to SQL 2005

I have a SQL Server 2000 linked to a SQL Server 2005 and I am attempting populate a temporary table on the 2000 server using INSERT INTO by executing a stored procedure on the 2005 server. If I just execute the stored procedure, the data is returened with no issues. If I try to Insert the data into the temporary table the process hangs and times out.

This returns the data with no issues:

EXEC @.RetVal = MyLink.MyTable.dbo.spGetValue @.string1

This hangs and has to be killed or times out:

CREATE TABLE #TempTable (Value DECIMAL(19, 10) NULL)
INSERT INTO #TempTable

EXEC @.RetVal = MyLink.MyTable.dbo.spGetValue @.string1
SELECT * FROM #TempTable

I tried adding SET REMOTE_PROC_TRANSACTIONS OFF as suggested in an earlier post, but this had no effect.

You need to turn the MSDTC service on. You can this by clicking START > SETTINGS > CONTROL PANEL > ADMINISTRATIVE TOOLS > SERVICES. Find the service called 'Distributed Transaction Coordinator' and RIGHT CLICK (on it and select) > Start.

|||

Thanks for your reply.

MSDTC service is already running on both servers.

Monday, March 12, 2012

Problem with executing sql-query

When I execute this query, I get the error: 'The colum prefix 'ClassifiedAd does not match with a table'. But the table does exist. Does anyone know what's wrong?

select ca.ItemID,
ca.ModuleID,
'CreatedByUser' = u1.FirstName + ' ' + u1.LastName,
ClassifiedAd.CreatedDate,
'UpdatedByUser' = u2.FirstName + ' ' + u2.LastName,
ca.UpdatedDate,
ca.AdTitle,
ca.AdText,
ca.AdHasImage,
ca.AdPOCName,
ca.AdPOCEmail,
ca.AdPOCPhone
from ClassifiedAd ca
left outer join Users u1 on ca.CreatedByUser = u1.UserID
left outer join Users u2 on ca.UpdatedByUser = u2.UserID
where ca.ItemID = 1
and ca.ModuleId = 1No it doesn't you've renamed it as "ca"

problem with executing sp_addrolemember...

When I login localy (computer with sql server) I can call procedure sp_addrolemember but when I am loged in remotely (from client computer)and try to call the same procedure I get this message: 'User does not have permission to performe this action'.

hi

executing the procedure requires membership to db_owner or db_securityadmin database roles so that has nothing to do with workstation but with principals and thus logins...

verify the login you are connecting with from the remote client is mapped to a database user with enought permissions..

regards

Problem with executing Distributed Transactions on Linked Servers

I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle
Database.
The Link is perfect and dont have any problems in accessing the data
from ORACLE. The only problem i am facing is when i am trying
to initiate a Distributed transaction. A simple Insert Query is
working fine but when i try to perform the same through a Stored
Procedure having the Begin Transaction i am getting the error
mentioned below.
Server: Msg 7391, Level 16, State 1, Procedure InsertGFSTemp, Line 12
The operation could not be performed because the OLE DB provider
'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA'
ITransactionJoin::JoinTransaction returned 0x8004d01b].
I have tried all the help available and have all the supported
softwares installed as well on the SQL Server machine. Still facing
this problem.
If anybody could help me with the same.
Hi!
The error 7391 troubleshooting guide is at
http://support.microsoft.com/default...;en-us;306212. Check it, it
might help you.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Raja" <Raja@.discussions.microsoft.com> wrote in message
news:F74A2D92-C765-4A09-A5C7-903CB7C92E9D@.microsoft.com...
> I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle
> Database.
> The Link is perfect and dont have any problems in accessing the data
> from ORACLE. The only problem i am facing is when i am trying
> to initiate a Distributed transaction. A simple Insert Query is
> working fine but when i try to perform the same through a Stored
> Procedure having the Begin Transaction i am getting the error
> mentioned below.
> Server: Msg 7391, Level 16, State 1, Procedure InsertGFSTemp, Line 12
> The operation could not be performed because the OLE DB provider
> 'MSDAORA' was unable to begin a distributed transaction.
> OLE DB error trace [OLE/DB Provider 'MSDAORA'
> ITransactionJoin::JoinTransaction returned 0x8004d01b].
> I have tried all the help available and have all the supported
> softwares installed as well on the SQL Server machine. Still facing
> this problem.
> If anybody could help me with the same.
>
|||"=?Utf-8?B?UmFqYQ==?=" <Raja@.discussions.microsoft.com> wrote in
news:F74A2D92-C765-4A09-A5C7-903CB7C92E9D@.microsoft.com:

> oblem i am facing is when i am trying
> to initiate a Distributed transaction. A simple Insert Query is
> working fine but when i try to perform the same through a Stored
> Procedure having the Begin Transaction i am getting the error
> mentioned below.
>
You need to SET IMPLICIT_TRANSACTIONS OFF
See BOL: SET IMPLICIT_TRANSACTIONS

Problem with executing Distributed Transactions on Linked Servers

I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle
Database.
The Link is perfect and dont have any problems in accessing the data
from ORACLE. The only problem i am facing is when i am trying
to initiate a Distributed transaction. A simple Insert Query is
working fine but when i try to perform the same through a Stored
Procedure having the Begin Transaction i am getting the error
mentioned below.
Server: Msg 7391, Level 16, State 1, Procedure InsertGFSTemp, Line 12
The operation could not be performed because the OLE DB provider
'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA'
ITransactionJoin::JoinTransaction returned 0x8004d01b].
I have tried all the help available and have all the supported
softwares installed as well on the SQL Server machine. Still facing
this problem.
If anybody could help me with the same.Hi!
The error 7391 troubleshooting guide is at
http://support.microsoft.com/default.aspx?scid=kb;en-us;306212. Check it, it
might help you.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Raja" <Raja@.discussions.microsoft.com> wrote in message
news:F74A2D92-C765-4A09-A5C7-903CB7C92E9D@.microsoft.com...
> I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle
> Database.
> The Link is perfect and dont have any problems in accessing the data
> from ORACLE. The only problem i am facing is when i am trying
> to initiate a Distributed transaction. A simple Insert Query is
> working fine but when i try to perform the same through a Stored
> Procedure having the Begin Transaction i am getting the error
> mentioned below.
> Server: Msg 7391, Level 16, State 1, Procedure InsertGFSTemp, Line 12
> The operation could not be performed because the OLE DB provider
> 'MSDAORA' was unable to begin a distributed transaction.
> OLE DB error trace [OLE/DB Provider 'MSDAORA'
> ITransactionJoin::JoinTransaction returned 0x8004d01b].
> I have tried all the help available and have all the supported
> softwares installed as well on the SQL Server machine. Still facing
> this problem.
> If anybody could help me with the same.
>|||"=?Utf-8?B?UmFqYQ==?=" <Raja@.discussions.microsoft.com> wrote in
news:F74A2D92-C765-4A09-A5C7-903CB7C92E9D@.microsoft.com:
> oblem i am facing is when i am trying
> to initiate a Distributed transaction. A simple Insert Query is
> working fine but when i try to perform the same through a Stored
> Procedure having the Begin Transaction i am getting the error
> mentioned below.
>
You need to SET IMPLICIT_TRANSACTIONS OFF
See BOL: SET IMPLICIT_TRANSACTIONS

Problem with executing Distributed Transactions on Linked Server

I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle
Database.
The Link is perfect and dont have any problems in accessing the data
from ORACLE. The only problem i am facing is when i am trying
to initiate a Distributed transaction. A simple Insert Query is
working fine but when i try to perform the same through a Stored
Procedure having the Begin Transaction i am getting the error
mentioned below.
Server: Msg 7391, Level 16, State 1, Procedure InsertGFSTemp, Line 12
The operation could not be performed because the OLE DB provider
'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA'
ITransactionJoin::JoinTransaction returned 0x8004d01b].
I have tried all the help available and have all the supported
softwares installed as well on the SQL Server machine. Still facing
this problem.
If anybody could help me with the same.
Raja,
That error code you are getting - " 0x8004d01b" translates into - "The
Transaction Manager is not available". I think that seems to be the
problem. What are the OS of the boxes involved?
Thanks,
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.

Problem with executing Distributed Transactions on Linked Server

I have a Linked Server i.e. my SQL Server 2000 is Linked to the Oracle
Database.
The Link is perfect and dont have any problems in accessing the data
from ORACLE. The only problem i am facing is when i am trying
to initiate a Distributed transaction. A simple Insert Query is
working fine but when i try to perform the same through a Stored
Procedure having the Begin Transaction i am getting the error
mentioned below.
Server: Msg 7391, Level 16, State 1, Procedure InsertGFSTemp, Line 12
The operation could not be performed because the OLE DB provider
'MSDAORA' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'MSDAORA'
ITransactionJoin::JoinTransaction returned 0x8004d01b].
I have tried all the help available and have all the supported
softwares installed as well on the SQL Server machine. Still facing
this problem.
If anybody could help me with the same.Raja,
That error code you are getting - " 0x8004d01b" translates into - "The
Transaction Manager is not available". I think that seems to be the
problem. What are the OS of the boxes involved?
Thanks,
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.

problem with executing an sqlcommand

when i push a button my datagrid doesn't show up. please help this is my code. I only try to execute one of the sql command and when i push the button it just redirects me to my homepage.

Private Sub btnbid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbid.Click

Dim conn As New SqlConnection((Application("SQL_Connection_String")))

conn.Open()

Dim cmdbid As New SqlCommand("insert into Bids (CustID,ItemCode,BidAmount) values (@.CustID,@.ItemCode,@.BidAmount)", conn)

cmdbid.Parameters.Add("@.CustID", SqlDbType.Int, 4)
cmdbid.Parameters("@.CustID").Value = Session("CustID")
cmdbid.Parameters.Add("@.ItemCode", SqlDbType.Int, 4)
cmdbid.Parameters("@.ItemCode").Value = CInt(Request.QueryString("Id"))
cmdbid.Parameters.Add("@.BidAmount", SqlDbType.Decimal, 9)
cmdbid.Parameters("@.BidAmount").Value = CDec(txtbidamount.Text)

Dim cmdhighbid As New SqlCommand("update items set Highestbid=@.BidAmount,HighestBidder=@.bidder where ItemCode=@.ItemCode and Highestbid<@.BidAmount", conn)

cmdhighbid.Parameters.Add("@.BidAmount", SqlDbType.Decimal, 9)
cmdhighbid.Parameters("@.BidAmount").Value = CDec(txtbidamount.Text)
cmdhighbid.Parameters.Add("@.bidder", SqlDbType.Int, 4)
cmdhighbid.Parameters("@.bidder").Value = Session("CustID")
cmdhighbid.Parameters.Add("@.ItemCode", SqlDbType.Int, 4)
cmdhighbid.Parameters("@.ItemCode").Value = Request.QueryString("Id")

Try
cmdbid.ExecuteNonQuery()

lblbidstatus.Text = "Bid Inserted Successfully!! Good Luck!!!"
Catch ex As Exception

lblbidstatus.Text = ex.Message
End Try

btnbid.Enabled = False
conn.Close()
End Subare you binding the datagrid within if not ispostback loop in page_load.. ?

hth|||i don't have anything in the page load only the bindgrid() proc.|||because you are prbly losing the datagrid during postbck. try this


sub page_load(...)
if not ispostback() then
bindgrid()
end if
end sub

hth|||no that's not the problem. when i push the button it redirects me to the homepage with no reason and does not do any changes i do with the sql command|||i dont see anything in your code to redirect to another page. are you sure you are calling the right event ?

Problem with executing a SQL Server DTS Package from ASP

Could someone help. I am new at writing scripts to execute a DTS package using ASP. After I run my scripts, I get the following error message :

Step [DTSStep_DTSDataPumpTask_1] failed
Task "Import FITA Calendar"

Package [Import Fita Calendar] failed

Here is what my scripts look like :

<%
Const DTSSQLStgFlag_Default = 0
Const DTSStepExecResult_Failure = 1

Dim oPkg, oStep, sMessage, bStatus

Set oPkg = Server.CreateObject("DTS.Package")
oPkg.LoadFromSQLServer "myserver","sa","$12eww",DTSSQLStgFlag_Default,"","","","Import FITA calendar"
oPkg.Execute()

bStatus = True

For Each oStep In oPkg.Steps
sMessage = sMessage & "<p> Step [" & oStep.Name & "] "
If oStep.ExecutionResult = DTSStepExecResult_Failure Then
sMessage = sMessage & " failed<br>"
bStatus = False
Else
sMessage = sMessage & " succeeded<br>"
End If
sMessage = sMessage & "Task """ & oPkg.Tasks (oStep.TaskName).Description & """</p>"
Next

If bStatus Then
sMessage = sMessage & "<p>Package [" & oPkg.Name & "] succeeded</p>"
Else
sMessage = sMessage & "<p>Package [" & oPkg.Name & "] failed</p>"
End If

Response.Write sMessage
Response.Write "<p>Done</p>"

%>because I do that alot. And you can exec DTS inside SP. So you can place this inside your sp and just exec from asp. Hope that helps.

example

exec master..xp_cmdshell 'dtsrun /Ssql1 /NPublish /E'
This will execute the DTSRun command line utility with the parameters

/S = SQL Server Host Name
/N = DTS Package Name
You can either use /E for "trusted connection" or /U/P to supply username and passwords

Friday, March 9, 2012

Problem with dynamic sql statement

Can someone tell me why this is not executing properly. No error
messages, just no rows returned. I need to have an output parameter
and a return value.
Thanks in advance
Julie Barnet
CREATE PROCEDURE dbo.sel_LookupChar
(
@.Lookup_Value NVarChar(30),
@.Lookup_Field NVarChar(30),
@.Lookup_Table NVarChar(30),
@.MyOutput nVarChar(100) OUTPUT
)
AS
Declare @.SqlStr VarChar(1000)
Select @.SqlStr = "Select " + @.MyOutput + " = " + @.Lookup_Field + "
From " + @.Lookup_Table + " Where " + @.Lookup_Field
Select @.SqlStr = @.SqlStr + " = '" + @.Lookup_Value + "'"
Exec(@.SqlStr)
return @.@.rowcount
GOUse ' not " for string delimiters.
Also, try PRINT @.SqlStr instead of EXEC, and show us the result.
"Julie Barnet" <barnetj@.pr.fraserpapers.com> wrote in message
news:438e1811.0308270858.4563cc29@.posting.google.com...
> Can someone tell me why this is not executing properly. No error
> messages, just no rows returned. I need to have an output parameter
> and a return value.
> Thanks in advance
> Julie Barnet
> CREATE PROCEDURE dbo.sel_LookupChar
> (
> @.Lookup_Value NVarChar(30),
> @.Lookup_Field NVarChar(30),
> @.Lookup_Table NVarChar(30),
> @.MyOutput nVarChar(100) OUTPUT
> )
> AS
> Declare @.SqlStr VarChar(1000)
> Select @.SqlStr = "Select " + @.MyOutput + " = " + @.Lookup_Field + "
> From " + @.Lookup_Table + " Where " + @.Lookup_Field
> Select @.SqlStr = @.SqlStr + " = '" + @.Lookup_Value + "'"
>
> Exec(@.SqlStr)
> return @.@.rowcount
> GO

Saturday, February 25, 2012

problem with DBLib access to SQL Server 2005

Hi all,
I'm having a (probably) fundamental problem executing an insert statement on
SQL Server 2005 from an app written in plain C, using the DBLib API. Please
DO NOT comment on the fact the DBlib is obsolete, I know it is. It's just th
e
fastest way with the least overhead, and as such my method of choice and
currently still available with SQL Server 2005.
All appears to go well for the init, login and begin transaction calls. The
first and any subsequent inserts however cause dbresults to return 2, which,
depending on where and what in the docs you want to believe, means
NO_MORE_RESULTS. In the context of an insert, that doesn't make much sense.
In any case, the data did not get inserted.
When I keep SQL Monitor open during those calls, I see the calls are being
made, the insert statements transferred, and when I copy/paste them into the
SQL Manager window and execute them, they work just fine, no syntax problems
there.
Here are a few code snippets, maybe somebody can see where I'm messing up.
the database init:
// Initialize DB-Library.
dbinit();
// Get a LOGINREC.
login = dblogin ();
DBSETLSECURE (login);
DBSETLAPP(login, "mydb");
DBSETLUSER(login, "TITAN\\user");
// Get a DBPROCESS structure for communication with SQL Server.
dbproc = dbopen(login, "Titan");
//switch the default database to the mydb DB:
dbcmd (dbproc, "EXEC sp_defaultdb 'sa', 'mydb'");
dbsqlexec (dbproc);
This part does not produce any error messages. I'm logging into sql server
as the logged in user, which should be the sa in my default environment.
Then, I initiate a transaction. Each transaction will consist of about
20'000 inserts:
strcpy_s(cBuf, sizeof(cBuf), "BEGIN TRANSACTION");
// Send the command to SQL Server and start execution.
dbcmd (dbproc, cBuf);
dbsqlexec (dbproc);
// Process the results.
rc = dbresults (dbproc);
if (rc != SUCCEED && rc != NO_MORE_RESULTS) {
printf("Command failed: %s", cBuf);
dbexit();
exit(1);
}
This returns rc = 1 (i.e. SUCCEED).
Then I begin with the insert statement:
dbcmd (dbproc, "INSERT INTO data (\"Field1\") VALUES (-12);");
rc = dbsqlexec (dbproc);
// Process the results.
rc = dbresults(dbproc);
if (rc != SUCCEED && rc != NO_MORE_RESULTS) {
fprintf(stderr, "dbresults returned: %d\n", rc);
dbexit();
exit(1);
}
Now, rc = 2. Why? The same statement executed in the SQL Server Manager
window works just fine, the same statement in SQLite worked just fine as wel
l
(actually, the " were ' and had to be changed to " because SQL Server
complained about syntax).
This happens regardless of whether I start with a "BEGIN TRANSACTION" call
or not.
Cheers
- BaltBalt,

fastest way with the least overhead, and as such my method of choice and
currently still available with SQL Server 2005. <<<
Actually it is not still available with 2005 you have to get it from a
previous version to even use it. It is obsolete for a reason and your
excuse for using it simply will not cut it. Even if you get thru this
hurdle you will ultimately hit another. If you are trying to insert 20K rows
as fast as possible I suggest you use one of the newer bulk insert api's
instead. I know this is not what you wanted to hear but this is a loosing
proposition in the long run.
Andrew J. Kelly SQL MVP
"Balt" <Balt@.discussions.microsoft.com> wrote in message
news:CBB6F9F3-711F-4837-B831-C62DEA5F411A@.microsoft.com...
> Hi all,
> I'm having a (probably) fundamental problem executing an insert statement
> on
> SQL Server 2005 from an app written in plain C, using the DBLib API.
> Please
> DO NOT comment on the fact the DBlib is obsolete, I know it is. It's just
> the
> fastest way with the least overhead, and as such my method of choice and
> currently still available with SQL Server 2005.
> All appears to go well for the init, login and begin transaction calls.
> The
> first and any subsequent inserts however cause dbresults to return 2,
> which,
> depending on where and what in the docs you want to believe, means
> NO_MORE_RESULTS. In the context of an insert, that doesn't make much
> sense.
> In any case, the data did not get inserted.
> When I keep SQL Monitor open during those calls, I see the calls are being
> made, the insert statements transferred, and when I copy/paste them into
> the
> SQL Manager window and execute them, they work just fine, no syntax
> problems
> there.
> Here are a few code snippets, maybe somebody can see where I'm messing up.
> the database init:
> // Initialize DB-Library.
> dbinit();
> // Get a LOGINREC.
> login = dblogin ();
> DBSETLSECURE (login);
> DBSETLAPP(login, "mydb");
> DBSETLUSER(login, "TITAN\\user");
>
> // Get a DBPROCESS structure for communication with SQL Server.
> dbproc = dbopen(login, "Titan");
> //switch the default database to the mydb DB:
> dbcmd (dbproc, "EXEC sp_defaultdb 'sa', 'mydb'");
> dbsqlexec (dbproc);
> This part does not produce any error messages. I'm logging into sql server
> as the logged in user, which should be the sa in my default environment.
> Then, I initiate a transaction. Each transaction will consist of about
> 20'000 inserts:
> strcpy_s(cBuf, sizeof(cBuf), "BEGIN TRANSACTION");
> // Send the command to SQL Server and start execution.
> dbcmd (dbproc, cBuf);
> dbsqlexec (dbproc);
> // Process the results.
> rc = dbresults (dbproc);
> if (rc != SUCCEED && rc != NO_MORE_RESULTS) {
> printf("Command failed: %s", cBuf);
> dbexit();
> exit(1);
> }
> This returns rc = 1 (i.e. SUCCEED).
> Then I begin with the insert statement:
> dbcmd (dbproc, "INSERT INTO data (\"Field1\") VALUES (-12);");
> rc = dbsqlexec (dbproc);
> // Process the results.
> rc = dbresults(dbproc);
> if (rc != SUCCEED && rc != NO_MORE_RESULTS) {
> fprintf(stderr, "dbresults returned: %d\n", rc);
> dbexit();
> exit(1);
> }
> Now, rc = 2. Why? The same statement executed in the SQL Server Manager
> window works just fine, the same statement in SQLite worked just fine as
> well
> (actually, the " were ' and had to be changed to " because SQL Server
> complained about syntax).
> This happens regardless of whether I start with a "BEGIN TRANSACTION" call
> or not.
> Cheers
> - Balt
>|||Balt (Balt@.discussions.microsoft.com) writes:
> All appears to go well for the init, login and begin transaction calls.
> The first and any subsequent inserts however cause dbresults to return
> 2, which, depending on where and what in the docs you want to believe,
> means NO_MORE_RESULTS. In the context of an insert, that doesn't make
> much sense.
Actually, it does. An INSERT statement will return a rowcount (the
thing you see as a ("1 row affected") in Query Analyzer or Mgmt Studio,
unless SET NOCOUNT ON.

> //switch the default database to the mydb DB:
> dbcmd (dbproc, "EXEC sp_defaultdb 'sa', 'mydb'");
> dbsqlexec (dbproc);
This seems like a very funny thing to do. And dangerous. Changing the
default database for sa is something I never had the guts to try.
And why would you change the default database for sa, when you logged
in with integrated security?

> This part does not produce any error messages. I'm logging into sql server
> as the logged in user, which should be the sa in my default environment.
No! "sa" is an SQL login, and you login with Integrated Security. If you
have admin rights in Windows, you will have symin rights in SQL Server,
but you will not be sa.

> Then, I initiate a transaction. Each transaction will consist of about
> 20'000 inserts:
As Andrew said, consider using bulk operations instead.
Another alternative is to build an XML document of all the 20000
rows, send that to SQL Server and then shred it into the target table(s).
If you really want to send row-by-row, use a stored procedure that you
call through RPC instead. This is faster, as you get a cached query plan,
and there is no need for parsing the query each time.
And if you don't want to use stored procedures, at least call
sp_executesql through RPC instead. Hm, wait, sp_executesql insists
on parameters on nvarchar that DB-Library cannot handle. So that won't
fly.
Anyway, whatever, don't send 20000 INSERT statements over the wire. It's
simple ineffecient.

> dbcmd (dbproc, "INSERT INTO data (\"Field1\") VALUES (-12);");
For this to work, the setting QUOTED_IDENTIFIER must be ON. Which it is
by default with ODBC, OLE DB and SqlClient. But not with DB-Library. So
you would need to issue SET QUOTED_IDENTIFIER ON from your program. Or
use [] to quote your identifiers instead.
Then again, I told you not to send INSERT statements.

> rc = dbsqlexec (dbproc);
> // Process the results.
> rc = dbresults(dbproc);
> if (rc != SUCCEED && rc != NO_MORE_RESULTS) {
> fprintf(stderr, "dbresults returned: %d\n", rc);
> dbexit();
> exit(1);
> }
> Now, rc = 2. Why?
Because there are no more results. But not from the INSERT statment.
You failed to check the return code from dbsqlexec, but I bet it says
FAIL. Because you previous call to dbresults return SUCCEED, and this
means that you have not cleared out the previous command, so you
get an error when trying to start a new one. You should always loop
over dbresults until it returns FAIL or NO_MORE_RESULTS.
Finally, there are tons of limitations you run into when you use
DB-Library, so it is very difficult to recommend it. It is a very nice
client API once you have learnt to master it. Particularly, it does not
perform tricks behind your back. However, it certainly has a taste
of black-and-white television these days.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Problem with DB_OWNER role..

Hi All,

I am facing a problem while executing a statement through C++ code
using OLEDB API of Sql server.
There is a problem with DB_OWNER role. If I will enable the DB_OWNER
everything is going fine but if I will remove this role than I am
getting error "DB_E_ERRORSINCOMMAND".

But if I will execute the same in query analyser it is going
absolutely fine in either case.
I am not able to understand why I am getting error while using API.

Please help me.....thanks in advancemonty (manishgandhi13@.gmail.com) writes:

Quote:

Originally Posted by

I am facing a problem while executing a statement through C++ code
using OLEDB API of Sql server.
There is a problem with DB_OWNER role. If I will enable the DB_OWNER
everything is going fine but if I will remove this role than I am
getting error "DB_E_ERRORSINCOMMAND".
>
But if I will execute the same in query analyser it is going
absolutely fine in either case.
I am not able to understand why I am getting error while using API.


I'm afraid that I need to ask for more information. What do you mean
with "enable the DB_OWNER role"? Do you mean that you add the user
you connect with to the DB_OWNER role?

Do you run with the same user from QA?

Have you examined the ISqlServerErrorInfo object to get the error message?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||On Aug 22, 2:46 am, Erland Sommarskog <esq...@.sommarskog.sewrote:

Quote:

Originally Posted by

monty (manishgandh...@.gmail.com) writes:

Quote:

Originally Posted by

I am facing a problem while executing a statement through C++ code
using OLEDB API of Sql server.
There is a problem with DB_OWNER role. If I will enable the DB_OWNER
everything is going fine but if I will remove this role than I am
getting error "DB_E_ERRORSINCOMMAND".


>

Quote:

Originally Posted by

But if I will execute the same in query analyser it is going
absolutely fine in either case.
I am not able to understand why I am getting error while using API.


>
I'm afraid that I need to ask for more information. What do you mean
with "enable the DB_OWNER role"? Do you mean that you add the user
you connect with to the DB_OWNER role?
>
Do you run with the same user from QA?
>
Have you examined the ISqlServerErrorInfo object to get the error message?
>
--
Erland Sommarskog, SQL Server MVP, esq...@.sommarskog.se
>
Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


yes by enabling the DB_OWNER i mean giving DB_OWNER role to the user.
And I am running with the same user in QA with which i am connecting
through API.

Also I have examined ISqlServerErrorInfo object to get the error
message because of that only I am getting error DB_E_ERRORSINCOMMAND.

Feel free to ask for more information....|||monty (manishgandhi13@.gmail.com) writes:

Quote:

Originally Posted by

yes by enabling the DB_OWNER i mean giving DB_OWNER role to the user.
And I am running with the same user in QA with which i am connecting
through API.
>
Also I have examined ISqlServerErrorInfo object to get the error
message because of that only I am getting error DB_E_ERRORSINCOMMAND.
>
Feel free to ask for more information....


I guess then I would need to see your code, including the error-handling
part...

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||On Aug 22, 3:31 pm, Erland Sommarskog <esq...@.sommarskog.sewrote:

Quote:

Originally Posted by

monty (manishgandh...@.gmail.com) writes:

Quote:

Originally Posted by

yes by enabling the DB_OWNER i mean giving DB_OWNER role to the user.
And I am running with the same user in QA with which i am connecting
through API.


>

Quote:

Originally Posted by

Also I have examined ISqlServerErrorInfo object to get the error
message because of that only I am getting error DB_E_ERRORSINCOMMAND.


>

Quote:

Originally Posted by

Feel free to ask for more information....


>
I guess then I would need to see your code, including the error-handling
part...
>
--
Erland Sommarskog, SQL Server MVP, esq...@.sommarskog.se
>
Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


it's ok...but i just want to know...do we need to have DB_OWNER role
for executing DDL statements through OLEDB API ??|||monty (manishgandhi13@.gmail.com) writes:

Quote:

Originally Posted by

it's ok...but i just want to know...do we need to have DB_OWNER role
for executing DDL statements through OLEDB API ??


DDL statements require at least membership in db_ddladmin, no matter how you
connect.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||On Aug 22, 6:56 pm, Erland Sommarskog <esq...@.sommarskog.sewrote:

Quote:

Originally Posted by

monty (manishgandh...@.gmail.com) writes:

Quote:

Originally Posted by

it's ok...but i just want to know...do we need to have DB_OWNER role
for executing DDL statements through OLEDB API ??


>
DDL statements require at least membership in db_ddladmin, no matter how you
connect.
>
--
Erland Sommarskog, SQL Server MVP, esq...@.sommarskog.se
>
Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


I am creating and using a temp table. For doing this db_ddladmin role
will be enough??|||monty (manishgandhi13@.gmail.com) writes:

Quote:

Originally Posted by

I am creating and using a temp table. For doing this db_ddladmin role
will be enough??


I'm sorry, but I would appreciate if you could post your actual code
or in other ways to give me sufficient information what you are doing.
If you insist on just providing pieces, the quality of the answers you
get will be poor.

To create temp tables you need no particular permissions at all.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx