Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Monday, March 26, 2012

Pooling

Im using SQL Express and ADO.

The connection string im using is

"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=mydatabase;Data Source=TESTBOX\SQLEXPRESS"

The problem i have is there are lots of alerts generated in the security evenlog which are login events almost every second. Our app has many different threads and processes accesing the same database in a Queue fashion. What im concerned by looking at these logs and also looking at the connections opened is that i see all the connections open and close every second and so no connection pooling is happening.

Am i missing something ?

The connection pool is security context specific. When you are using integrated security, each individual user will have their own connection pool.

It is not unusual for a heavily used production server to generate hundreds of login alerts (maybe even thousands) per second. If appropriate for your situation, you may choose to change the alerts to log only Login Failures (and ignore Login successes. )

|||

Thanks for the reply. The services are the ones doing all the calls into SQL. It is always only one user ( The service is running as this user) And i dont see any connection being active for more than a few ms. And i think that means that the connection pool is not even getting created . no ?

but if connection pooling is happening then how can see thousands of logins ? is it not supposed to use the existing connection in the pool and not relogin to SQL ?

Arnie Rowland wrote:

The connection pool is security context specific. When you are using integrated security, each individual user will have their own connection pool.

It is not unusual for a heavily used production server to generate hundreds of login alerts (maybe even thousands) per second. If appropriate for your situation, you may choose to change the alerts to log only Login Failures (and ignore Login successes. )

|||

Having the Login Success/Failure events write to Event Log has little direct relationship with the connection. It has everything to do with security.

One connection pool will still generate an Event Log entry every time there is a query from any user. Every incoming query will have the users' access and/or permissions validated.

If you don't want to have Login Successes filling up your Event Log, then you can change that to Log only Failures. -Or not at all.

|||

ok. but if i set the username password as userid=sa , password then i dont see any events.

btw how do i even see if connection pool is being created or not ?

|||

Take look at this site

http://support.microsoft.com/default.aspx/kb/166083

|||

To determine if connection pooling is happening in the ADO/OLEDB you can enable tracing using the following whitepaper: http://msdn2.microsoft.com/en-us/library/aa964124.aspx.From your connection string you’re using SQLOLEDB which will require that you’re at least on MDAC 2.8 SP2 to get complete tracing.

Hope this helps.

|||Use SQL Profiler and see if you get sp_reset_connection calls. If you do, then you have connection pooling working, otherwise you will see new connections.

You might be destroying the pool if you do not hold onto at least one connection.
There is a performance optimization for COM+ and IIS scenarios, but for a standalone application make sure you do not release everything. For instance in the following ADO code:

For i = 1 To 100

c.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;OLE DB Services=-1; Data Source=.; Initial Catalog=pubs;"

Set r = New ADODB.Recordset

r.Open "SELECT * FROM Authors", c

Set r = Nothing

c.Close

Set c = Nothing

Next I

As soon as you set c to Nothing and don't have other active connections you are going to destroy the whole oledb session pool.

Monday, March 12, 2012

PLS HELP:Merge cells - use cursor?

Hi,
I just wonder if someone could help me here:
Say, i have a table with one column: 'Name'
Name1
Name2
Name3
...
I need to get the string of "Name1, Name2, Name3, ..."
The only way i see is to use cursor - but i know cursors aren't the best way
if an alternative exists...
So is there a way to just use a select to perform that?
Thank you,
AndreyYes, I think you'll need to visit each row.
However instead of using a cursor, try using a table variable (excuse any
typos)
declare @.OutputList varchar(8000)
set @.OutputList=''
declare @.Rows integer
declare @.Val varchar(255)
declare @.I integer
declare @.T1 table (RowNum integer identity(1,1) primary key, RowData
varchar(255))
insert @.T1 select name from YourTable
set @.Rows = @.@.ROWCOUNT
if @.Rows<>0
begin
set @.I=0
while @.I<@.Rows
begin
set @.I=@.I+1
select @.Val=@.T1.RowData where @.T1.RowNum = @.I
set @.OutputList = @.OutputList + @.Val + ','
end
set @.OutputList = left(@.OutputList,Len(@.OutputList)-1) -- get rid of final
comma
end
....gtr
"MuZZy" wrote:

> Hi,
> I just wonder if someone could help me here:
> Say, i have a table with one column: 'Name'
> Name1
> Name2
> Name3
> ...
> I need to get the string of "Name1, Name2, Name3, ..."
> The only way i see is to use cursor - but i know cursors aren't the best w
ay if an alternative exists...
> So is there a way to just use a select to perform that?
> Thank you,
> Andrey
>|||Isn't that just a matter of formatting the output for display? So do it
in the client app, which is where presentation belongs and where it's
generally easier to do this kind of thing.
Otherwise, maybe something like this will help:
CREATE TABLE Foo (name VARCHAR(10) PRIMARY KEY)
SELECT
MAX(CASE ord WHEN 1 THEN name END)+
MAX(CASE ord WHEN 2 THEN ','+name ELSE '' END)+
MAX(CASE ord WHEN 3 THEN ','+name ELSE '' END)+
MAX(CASE ord WHEN 4 THEN ','+name ELSE '' END)+
MAX(CASE ord WHEN 5 THEN ','+name ELSE '' END)
/* repeat as required... */
FROM
(SELECT P.name, COUNT(*)
FROM Foo AS P,Foo AS Q
WHERE P.name >= Q.name
GROUP BY P.name) AS T(name,ord)
David Portas
SQL Server MVP
--

Friday, March 9, 2012

Please tell me why @@Error is not picking up the error

in this procedure the Gender column is a bit datatype. as you can see i'am adding a string.

when i exec proc my error message "print 'error'" is not showing. please help.

you can email at cbmorton!at!gmail.com

CREATE PROCEDURE [dbo].[sp_newuserregistration] AS
BEGIN TRAN
INSERT INTO UserLoginInfo (UserName,[Password]) values ('?','?')
SELECT @.@.IDENTITY AS 'Identity'
DECLARE @.UserID AS INT
SET @.UserID = @.@.Identity
INSERT INTO UserAccountInfo (UserID, Email) VALUES (@.UserID, '?')
INSERT INTO UserProfileInfo (UserID, FirstName, LastName, Gender, DateOfBirth) VALUES (@.UserID, '?', '?', 'x', null)
IF @.@.ERROR <> 0
BEGIN
PRINT 'error'

ROLLBACK TRAN
END
ELSE
BEGIN
COMMIT TRAN
END


GO

--EXEC sp_newuserregistration

The batch stops executing on the error and you can not catch it. You will need to use try/catch but it is only available in SQL Server 2005.|||? As Andreas mentioned, this is a batch-aborting exception -- for this reason, I usually like to use SET XACT_ABORT in my stored procedures that use transactions. Setting that option to ON will cause the transaction to automatically roll back in case of an exception. You might want to read the following articles for more background on all of this: http://www.sommarskog.se/error-handling-I.html http://www.sommarskog.se/error-handling-II.html -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <codrakon@.discussions.microsoft.com> wrote in message news:2db52d22-6890-435c-92c1-e794a3077677@.discussions.microsoft.com... in this procedure the Gender column is a bit datatype. as you can see i'am adding a string. when i exec proc my error message "print 'error'" is not showing. please help. you can email at cbmorton!at!gmail.com CREATE PROCEDURE [dbo].[sp_newuserregistration] ASBEGIN TRANINSERT INTO UserLoginInfo (UserName,[Password]) values ('?','?')SELECT @.@.IDENTITY AS 'Identity'DECLARE @.UserID AS INTSET @.UserID = @.@.Identity INSERT INTO UserAccountInfo (UserID, Email) VALUES (@.UserID, '?')INSERT INTO UserProfileInfo (UserID, FirstName, LastName, Gender, DateOfBirth) VALUES (@.UserID, '?', '?', 'x', null)IF @.@.ERROR <> 0BEGINPRINT 'error' ROLLBACK TRANENDELSEBEGINCOMMIT TRANEND GO --EXEC sp_newuserregistration