473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

WinService LogOn Event insert Sql Server Db

Hi,
i m not much good in windows services. wanna create one so when a user logIn (to his system) it inserts the time with userid in Sql server db. and same at logoff

How catch event for logon/off?

Thanx

Expand|Select|Wrap|Line Numbers
  1. protected override void OnStart(string[] args)
  2.         {   
  3.             eventLog1.WriteEntry("In OnStart Service");
  4.  
  5.  
  6.             SqlConnection con = new SqlConnection();
  7.  
  8.             con = new SqlConnection(@"Data Source=.\SQLEXPRESS;database=DB;User Id=sa; Password=sa; Integrated Security=SSPI;");
  9.  
  10.             con.Open();
  11.  
  12.             SqlCommand cmd = new SqlCommand("MySp", con);
  13.             cmd.CommandType = CommandType.StoredProcedure;
  14.             cmd.Parameters.Add("@CountryName", "Sudan");
  15.             cmd.ExecuteNonQuery();
  16.  
  17.         }
Feb 23 '10 #1
2 1788
sashi
1,754 Expert 1GB
The best method would be using 'sp_who' , "sp_who2" to see which user is connected to which database.
Feb 23 '10 #2
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Feb 23 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Newbie | last post by:
I have set up an ASP script (with some help from microsoft.public.inetserver.asp.general!) that grabs the windows username of the user and puts it into an Access database. It is setup on IIS5 as a...
3
by: cs | last post by:
I started a winservice on VS.NET and it was all going fine, I wrote over 500 lines of code and wanted to test them without installing the service, so I added a main method and set a starting point...
0
by: satti | last post by:
Hi, I have the following problem: I want to enable data transfer between my WinService and the Desktop I tried to set the flag manually in the Registry at...
6
by: Alixx Skevington | last post by:
OK why does the following code work in a Windows form with a crystal report viewer but not in a webform. I get the usual CrystalReports.EngineLogONException logon Failed when this is called in...
10
by: et | last post by:
I have an asp.net program that uses a connection string, using integrated security to connect to a sql database. It runs fine on one server, but the other server gives me the error that "Login...
2
by: Doug | last post by:
I've installed ASP.NET onto our web server (Win2k/unsure of IIS version) this morning. I created a simple ASPX page in Notepad that writes out an asp:Label control to the page and dynamically...
5
by: Paal Berggreen | last post by:
I am involved with development of a Portal solution using ASP.NET 2.0 and WebParts. The WebParts framework use the default personalization providers, and the personalization data thus ends up in...
0
by: robpimentel | last post by:
Hi, I've been using DB2 for about 1 week, so please bear with me. DB2 Connect Enterprise Edition v8.1 FixPack 5 Windows Server 2003 Standard Edition SP1 Here is an error that continues to...
4
by: J055 | last post by:
Hi I have 2 update buttons in my FormView ('Apply' and 'OK'). I want both buttons to update the data source but the 'OK' button should redirect afterwards. I can see which button is clicked...
1
by: cactuscrust | last post by:
I'm running IIS6 Windows2003, and as you'll see very quickly.. I'm pretty new to this stuff. Lately I've been getting bombarded with login attempts.... sometimes several in the same second, and it...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.