Click here to Skip to main content
15,888,113 members
Home / Discussions / C#
   

C#

 
QuestionREG: C# tutorials Pin
Member 825718321-Sep-11 17:52
Member 825718321-Sep-11 17:52 
AnswerRe: REG: C# tutorials Pin
Luc Pattyn21-Sep-11 18:28
sitebuilderLuc Pattyn21-Sep-11 18:28 
GeneralRe: REG: C# tutorials Pin
Mycroft Holmes21-Sep-11 19:37
professionalMycroft Holmes21-Sep-11 19:37 
QuestionCreating an ActiveX control to work in PowerPoint Pin
Wjousts21-Sep-11 10:50
Wjousts21-Sep-11 10:50 
GeneralSettings not saving correctly. Pin
Herboren21-Sep-11 7:56
Herboren21-Sep-11 7:56 
GeneralRe: Settings not saving correctly. Pin
Eddy Vluggen21-Sep-11 9:51
professionalEddy Vluggen21-Sep-11 9:51 
GeneralRe: Settings not saving correctly. Pin
BillWoodruff22-Sep-11 4:18
professionalBillWoodruff22-Sep-11 4:18 
QuestionNamespace problem Pin
CCodeNewbie21-Sep-11 5:45
CCodeNewbie21-Sep-11 5:45 
Greetings Gurus...

If you could spare a moment..?

The following code is an attempt to retrieve the contents of the Windows Application event log and upload the data to a SQL server.

I am getting 2 errors though and was hoping someone could tell me why the errors are occurring.

Error 1: "A namespace does not directly contain members such as fields or methods" at the line that reads
" SysMonConn.Open();" in bold
Error 2: "Type or namespace definition, or end-of-file expected" at the closing bracket.

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Data.SqlClient;

namespace ConsoleApplication3
{
    class Program
    {
        public static void Main();
           
            string logType = "Application";
            EventLog ev = new EventLog(logType, System.Environment.MachineName);
            EventLogEntry Entry = ev.Entries;

            SqlConnection SysMonConn = new SqlConnection(@"Provider = sqloledb.1" +
                                                         "Source = 192.168.x.y,1433" +
                                                         "Database = EventLogs" +
                                                         "Trusted_Connection=yes;" +
                                                         "user id=a;" +
                                                         "password=b;" +
                                                         "connection timeout=30;");
        }        
          SysMonConn.Open();
            SqlCommand SMCommand = SysMonConn.CreateCommand();
            SMCommand.CommandText = "INSERT INTO dbo.EventTable(Category, ComputerName," +
                                    "Message, SourceName, TimeWritten,Type, UserName)";
            SMCommand.Parameters.Add("@Category", System.Data.SqlDbType.NVarChar, 50) = Entry.Category;
            SMCommand.Parameters.Add("@ComputerName", System.Data.SqlDbType.NVarChar, 50) = Entry.MachineName;
            SMCommand.Parameters.Add("@Message", System.Data.SqlDbType.NVarChar, 250) = Entry.Message;
            SMCommand.Parameters.Add("@SourceName", System.Data.SqlDbType.NVarChar, 50) = Entry.Source;
            SMCommand.Parameters.Add("@TimeWritten", System.Data.SqlDbType.NVarChar, 50) = Entry.TimeWritten;
            SMCommand.Parameters.Add("@Type", System.Data.SqlDbType.NVarChar, 50) = Entry.EntryType;
            SMCommand.Parameters.Add("@UserName", System.Data.SqlDbType.NVarChar, 50) = Entry.UserName;
          
        ev.Close();
        
    }
}


Any assistance greatly appreciated Smile | :)
AnswerRe: Namespace problem Pin
Luc Pattyn21-Sep-11 6:12
sitebuilderLuc Pattyn21-Sep-11 6:12 
AnswerRe: Namespace problem Pin
RichardGrimmer21-Sep-11 6:12
RichardGrimmer21-Sep-11 6:12 
AnswerRe: Namespace problem Pin
Richard MacCutchan21-Sep-11 6:16
mveRichard MacCutchan21-Sep-11 6:16 
GeneralRe: Namespace problem Pin
CCodeNewbie21-Sep-11 6:47
CCodeNewbie21-Sep-11 6:47 
AnswerRe: Namespace problem Pin
Luc Pattyn21-Sep-11 7:09
sitebuilderLuc Pattyn21-Sep-11 7:09 
GeneralRe: Namespace problem Pin
CCodeNewbie21-Sep-11 7:24
CCodeNewbie21-Sep-11 7:24 
AnswerRe: Namespace problem Pin
Luc Pattyn21-Sep-11 7:34
sitebuilderLuc Pattyn21-Sep-11 7:34 
GeneralRe: Namespace problem Pin
CCodeNewbie21-Sep-11 7:48
CCodeNewbie21-Sep-11 7:48 
GeneralRe: Namespace problem Pin
Richard MacCutchan21-Sep-11 8:41
mveRichard MacCutchan21-Sep-11 8:41 
GeneralRe: Namespace problem Pin
lukeer21-Sep-11 21:00
lukeer21-Sep-11 21:00 
QuestionJava script -Print Pin
kathyani21-Sep-11 1:27
kathyani21-Sep-11 1:27 
AnswerRe: Java script -Print Pin
Pete O'Hanlon21-Sep-11 1:36
mvePete O'Hanlon21-Sep-11 1:36 
QuestionHotMail in ASP.net Pin
om_metab21-Sep-11 0:15
om_metab21-Sep-11 0:15 
AnswerRe: HotMail in ASP.net Pin
crocks25621-Sep-11 0:30
crocks25621-Sep-11 0:30 
AnswerRe: HotMail in ASP.net Pin
uspatel21-Sep-11 2:00
professionaluspatel21-Sep-11 2:00 
AnswerRe: HotMail in ASP.net Pin
RichardGrimmer21-Sep-11 6:14
RichardGrimmer21-Sep-11 6:14 
QuestionNot getting Output parameter value Pin
Hum Dum20-Sep-11 23:51
Hum Dum20-Sep-11 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.