Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Monday, March 19, 2012

[SQL2k5] Dynamic SQL Query Select on all user tables

In one query, I would like to query every user table in a specified database for

SELECT TOP (3) COUNT_BIG([Event Count]) AS EventNum, [Target IP], MAX([Time]) as LastSeen
GROUP BY [Target IP]
ORDER BY EventNum DESC

How is this possible?

Please give examples, I am a beginner.

Assume every table has the same structure for columns event count, target ip, and time.


Forgot, for every table it selects from, the table name must be one of the returned columns.|||

Hi, try the following:

sp_msforeachtable 'SELECT *,''?'' AS TableName FROM (SELECT TOP (3) , COUNT_BIG([Event Count]) AS EventNum, [Target IP], MAX([Time]) as LastSeen
FROM ?
GROUP BY [Target IP]
ORDER BY EventNum DESC) SubQuery'

But keep in mind that this should be just used for administrative task and adhoc queries not for business logic as the procedure is not documented, therefore not supported and could be deprecated in the next version of SQL Server.

HTH, Jens SUessmeyer.


http://www.sqlserver2005.de

Friday, February 24, 2012

[help] SQL Error - I/O Error 2 (The system cannot find the file specified)

Windows 2000 Server SP4 + SQL Server 2000 Enterprise Editon SP3,RAID5.

the windows event log give the following error information:

I/O error 2(The system cannot find the file specified) detected during write at offset 0x0000010c6c4000 in file 'D:\Program Files\Microsoft SQL Server\MSSQL\data\GJSZBANK_Data.MDF'.

I have searched microsoft knowledge base and got this article:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;828339

but don't understand some contents in the topic:

For example, if you encounter the following error message in the SQL Server Errorlog file, SQL Server encountered operating system error 2 when it uses a Windows API call to write to the tempdb primary database file:

Error: 823, Severity: 24, State: 4
I/O error 2(The system cannot find the file specified.) detected during write at offset 0x00000000284000 in file 'D:\Program Files\Microsoft SQL Server\MSSQL\data\tempdb.mdf'

Because SQL Server has already successfully opened the file and did not receive an Invalid Handle error, the error is likely being raised in a lower-level kernel software component, such as the file system or a device driver. This problem does not indicate a problem in SQL Server, and it must be investigated as an issue with the file system or a device driver that is associated with the file.

Does that mean this is not a SQL Server error?
Does that mean something wrong with my operating system? or something wrong with my hard disk?Are there any errors in the SQL errorlog? Or is it only in the NT Event log?

Sunday, February 19, 2012

[DBNETLIB] General Network Error - (I have included the event log dump.)

I have a MS MSDE 2000 database that is serving 3 database clients. Intermittently, randomly, and more important daily, my clients receive a "SQL Database Connection Error", and they are kicked out of the database. This appears to be correlated when they are writing/retrieving a record.

MS MSDE then writes the following error in it's event log.

----------
Source: SORules.Gateway.LogErrors
Process ID: 2328

Database connection lost
Error #-2147467259
[DBNETLIB][ConnectionWrite (send()).]General network error. Check your network documentation.
(Source: Microsoft OLE DB Provider for SQL Server)
(SQL State: 08S01)
(NativeError: 11)
No Help file available

OpenRsRead
System.Runtime.InteropServices.COMException (0x80004005): [DBNETLIB][ConnectionWrite (send()).]General network error. Check your network documentation.
at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options)
at SORules.Gateway.OpenRsRead(Command& C, Boolean& ForwardOnlyCursor)
Stack trace:
at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options)
at SORules.Gateway.OpenRsRead(Command& C, Boolean& ForwardOnlyCursor)
----------

Any help, suggestions, or thoughts would be greatly appreciated. This is for a small business line of business application that is critical for everyday business operations. These problems have resulted in lost work, short tempers, and a just frank frustration.

I am just getting started with MS SQL technologies and really need some quality help.

Thank you for your time, and have a great day.

Cheers,
MarkBasically this means that there is a "connection problem" between the client and server parts of the SQL Server software. The error isn't specific because there are way too many places for these kinds of problems to hide, most of which can't be found by the machine that notices the problem.

If the people are having regular network problems (slowness, problems reaching specific machines in their networks, web browsing issues, etc), then fixing those problems should also fix the SQL problem.

If they aren't having regular network problems, then you have to play a bit of Sherlock Holmes to track down the culprit. If I were in this situation, I'd check:

1. Visit the Windows Update site from each machine using SQL. Be sure to get the latest windows and driver patches.
2. Ping the database server from each machine, investigate any significant differences in ping times.
3. Check the Network Interface Card in each machine (including the server)
4. Check the network hardware (routers, etc)
5. Come back here if that doesn't help.

-PatP