Click here to Skip to main content
15,914,398 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to show a new record, and not the first (Windows Forms) Pin
Expert Coming14-Apr-08 13:04
Expert Coming14-Apr-08 13:04 
GeneralFindNext on BindingSource Pin
jchalfant14-Apr-08 8:56
jchalfant14-Apr-08 8:56 
AnswerRe: FindNext on BindingSource Pin
jchalfant14-Apr-08 10:45
jchalfant14-Apr-08 10:45 
QuestionUnboxing Question Pin
jka34714-Apr-08 8:39
jka34714-Apr-08 8:39 
GeneralRe: Unboxing Question Pin
Pete O'Hanlon14-Apr-08 9:10
mvePete O'Hanlon14-Apr-08 9:10 
GeneralRe: Unboxing Question Pin
jka34714-Apr-08 9:23
jka34714-Apr-08 9:23 
GeneralRe: Unboxing Question Pin
PIEBALDconsult14-Apr-08 17:29
mvePIEBALDconsult14-Apr-08 17:29 
GeneralSystem.NullException Error Pin
tcombs0714-Apr-08 8:26
tcombs0714-Apr-08 8:26 
Hey guys, I have this really weird issues and I can't seem to figure it out, the code list below run fine with no errors what so ever when I run it from a GUI application, but when i put it into a service and use it, it gives me a System.NullException error, but what is weird is that it gives me that error in the Finally Statement, but for some reason it doesn't even bother writing to the registry like it is suppose to, but it keep in mind the exact same code works if it is in a GUI application.

I have labeled the two lines that the error is given at.

Thanks for those who help.
Travis


using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Data.SqlClient;<br />
using System.Data;<br />
using Microsoft.Win32;<br />
<br />
    class VCS<br />
    {<br />
        private RegistryKey regKey;<br />
        private SqlDataReader rdr = null;<br />
        private SqlCommand cmd = null;<br />
        private string procValue;<br />
        private string connString<br />
            <br />
        private SqlConnection virasecConn = new SqlConnection();<br />
        <br />
        public void executeStorProc(string procedureName)<br />
        {<br />
            try<br />
            {<br />
                openConn();<br />
<br />
                cmd = new SqlCommand(procedureName, virasecConn);<br />
                cmd.CommandType = CommandType.StoredProcedure;<br />
<br />
                rdr = cmd.ExecuteReader();<br />
<br />
                while (rdr.Read())<br />
                {<br />
                    regKey = Registry.LocalMachine.OpenSubKey<br />
                    ("SOFTWARE\\VIRASEC, LLC\\VCS", true);<br />
<br />
                    procValue = rdr[0].ToString();<br />
<br />
                    regKey.SetValue("Test", procValue);<br />
                }<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Console.WriteLine(ex.Source + "\n" + ex.StackTrace);<br />
            }<br />
            finally<br />
            {<br />
                regKey.Close(); - Error occurs here      <br />
                rdr.Close(); - Error occurs here<br />
                closeConn(); <br />
            }         <br />
        }<br />
<br />
        public void openConn()<br />
        {<br />
            virasecConn.ConnectionString = connString;<br />
<br />
            try<br />
            {<br />
                virasecConn.Open();<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
               Console.WriteLine(ex.Source + "\n" + ex.StackTrace);<br />
            }<br />
        }<br />
<br />
        public void closeConn()<br />
        {<br />
            try<br />
            {<br />
                virasecConn.Close();<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Console.WriteLine(ex.Source + "\n" + ex.StackTrace);<br />
            }<br />
        }<br />
    }<br />
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Diagnostics;<br />
using System.ServiceProcess;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
<br />
    public partial class VCS_Service : ServiceBase<br />
    {<br />
        Thread threadOne = new Thread(new ThreadStart(mainThread)); <br />
        static VCS myVCS = new VCS();<br />
<br />
        public VCS_Service()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        protected override void OnStart(string[] args)<br />
        {<br />
            // TODO: Add code here to start your service.<br />
            threadOne.Start();<br />
        }<br />
<br />
        protected override void OnStop()<br />
        {<br />
            // TODO: Add code here to perform any tear-down necessary to stop your service.<br />
            threadOne.Abort();<br />
        }<br />
<br />
        public static void mainThread()<br />
        {<br />
            while (true)<br />
            {<br />
                myVCS.executeStorProc("GetWesHomeNumber");<br />
                Thread.Sleep(300000);<br />
            }<br />
        }<br />
       <br />
    }

GeneralRe: System.NullException Error Pin
Luc Pattyn14-Apr-08 9:01
sitebuilderLuc Pattyn14-Apr-08 9:01 
GeneralRe: System.NullException Error Pin
tcombs0714-Apr-08 9:29
tcombs0714-Apr-08 9:29 
GeneralRe: System.NullException Error Pin
Luc Pattyn14-Apr-08 9:56
sitebuilderLuc Pattyn14-Apr-08 9:56 
GeneralSQL statement Pin
vanessa12314-Apr-08 8:08
vanessa12314-Apr-08 8:08 
GeneralRe: SQL statement Pin
Rob Philpott14-Apr-08 8:18
Rob Philpott14-Apr-08 8:18 
GeneralRe: SQL statement Pin
Rob Philpott14-Apr-08 8:19
Rob Philpott14-Apr-08 8:19 
GeneralSerializing object. Need Help. Pin
zaboboa14-Apr-08 6:33
zaboboa14-Apr-08 6:33 
GeneralRe: Serializing object. Need Help. Pin
Zoltan Balazs14-Apr-08 7:23
Zoltan Balazs14-Apr-08 7:23 
GeneralC#: WriteEncrypedFileRaw Pin
rreeeddbb14-Apr-08 6:28
rreeeddbb14-Apr-08 6:28 
GeneralWindows Service Installer Pin
Madmaximus14-Apr-08 6:28
Madmaximus14-Apr-08 6:28 
General"The given path's format is not supported." Pin
shivapriyak14-Apr-08 4:36
shivapriyak14-Apr-08 4:36 
GeneralRe: "The given path's format is not supported." Pin
Mark J. Miller14-Apr-08 4:48
Mark J. Miller14-Apr-08 4:48 
GeneralRe: "The given path's format is not supported." Pin
J4amieC14-Apr-08 5:42
J4amieC14-Apr-08 5:42 
GeneralRe: "The given path's format is not supported." Pin
Mark J. Miller14-Apr-08 6:11
Mark J. Miller14-Apr-08 6:11 
GeneralRe: "The given path's format is not supported." Pin
J4amieC14-Apr-08 6:20
J4amieC14-Apr-08 6:20 
GeneralRe: "The given path's format is not supported." Pin
Mark J. Miller14-Apr-08 6:29
Mark J. Miller14-Apr-08 6:29 
GeneralRe: "The given path's format is not supported." Pin
PIEBALDconsult14-Apr-08 8:33
mvePIEBALDconsult14-Apr-08 8:33 

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.