Connection String not Initialized in Scheduled Task?

I am writing some code to send an email reminder to a number of people (gleaned from a database) at a scheduled time. When I run the .exe with windows task scheduler the email functionality works fine, but when I add the database piece it errors out with the following:
The Connection String property has not been initialized.
I am using the same code elsewhere in my application to make the db connection, so I can't see why it complains.
Here is the code:

using System;
using System.Data;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Mail;
using System.Data.SqlClient;
using System.Configuration;
namespace NewHire
public class EmailReminder
static protected System.Data.SqlClient.SqlConnection cn
= new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["str_cn"]);

static void Main(string[] args)
string to = "";
string from = "";
string subject = "test";
string body = "Success!";

string[] reqArray= new string[2];
SqlDataReader reader = GetPendingReqID().ExecuteReader();
reqArray[0] = reader[0].ToString();
body += reqArray[0];
SendEmail(to, from, subject, body, System.Web.Mail.MailFormat.Html);
public static void SendEmail(string To, string From, string
Subject, string Body, System.Web.Mail.MailFormat Format)
System.Web.Mail.MailMessage Mailer = new
Mailer.From = From;
Mailer.To = To;
Mailer.Subject = Subject;
Mailer.Body = Body;
Mailer.BodyFormat = Format;
static System.Data.SqlClient.SqlCommand GetPendingReqID()
System.Data.SqlClient.SqlCommand cmdGetPendingReqID =
new System.Data.SqlClient.SqlCommand("sp_GetPendingReqID", cn);
cmdGetPendingReqID.CommandType = CommandType.StoredProcedure;
// output params.
cmdGetPendingReqID.Parameters.Add("@ReqID", SqlDbType.Int);
cmdGetPendingReqID.Parameters["@ReqID"].Direction = ParameterDirection.Output;
return cmdGetPendingReqID;


Any suggestions much appreciated!
9/12/2003 8:56:11 PM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 44

Here's a thought - could the problem be that the EmailReminder.exe is essentially a console app, and I am trying to use web libraries? I have tried hardcoding in the connection string as follows:

cn.ConnectionString =
@"Data Source=server=IPofServer;" +
"Initial Catalog=DBNAme;" +
"User ID=username;" +

and get a System Error.
9/15/2003 4:22:51 PM

Similar Artilces:

how initialize a connection string in .Net
i am using a control that i downloaded from the control gallery It has a line for a connection string. which i put on in there: data source=server;initial catalog=database;user id=blahblah;password=557896 and i get an error: Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Define Connection String outside Web Form
How can I configure the Connection String outside the web form, maybe in the web.config file and use it in a data adapter ? In Web.Config, add an application specific setting: <system.web> <!-- OTHER STUFF --Z </system.web> <appSettings> <add key="conString" value="Server=localhost;UID=sa;PWD=Secret;Database=Northwind" /> <add key="CompanyName" value="Kullenberg" /> </appSettings> Call it where you need it: Dim con As String = ConfigurationSettings.appSettings(&q...

how to read connection string form Web.config ?
Hi,   how to read connection string form Web.config ? in ASP.NET 2005 ?   regards,,,   You may try this: ConfigurationSettings.AppSettings.Get("ConnectionStringName")  This posting is provided "AS IS" with no warranties, and confers no rights. or ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();...

web.config/ADO.NET command/connection string problem?
Ok, I have searched everywhere and not been able to find an answer yet so I hope someone can help me. I have an application that uses a key in the web.config file to reference a connection string to SQL Server 2000. In the development environment, this works as expected. However, when I edit the web.config file to reference a new database (initial catalog) it doesn't seem to register for some of the command objects (based on stored procs). I will receive an error that the user could not log on to database X, even though the connection should now be referencing database Y. This only happens w...

PB 11 .Net Web Form return a simple string?
Is it possible to create a pb 11 webform app that will accept input parms and return a simple string in response? Not trying to convert an existing app, I just want to be able to create web forms that can accept input parms, query a database to determine the answer based on the parms, and then return the answer in string format. For example, if I typed in the following url it might return "John Doe" as a simple string. WebForm is the wrong direction. You can create a .net assembly and use this inside asp. No big deal. ...

Connection Pooling
Hi Environment: PowerBuilder 11.1, Oracle 9i server (release 2), .NET web form application, IE I am trying to use connection pooling with ADO.NET Oracle.DataAccess.Client provide. But It seems to the connection pooling is not working properly. Below is my code: In applications open event: -------------------------- SQLCA.DBMS = "ADO.Net" SQLCA.LogPass = "myuser" SQLCA.LogId = "myuser" SQLCA.AutoCommit = False SQLCA.DBParm = "Namespace='Oracle.DataAccess.Client',ADORelease='',DataSource='bydatabase',PROV...

Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application
 Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application  please help me? Friend, Web.config has its own advantages. 1) Web.Config is used to store the important information like connections strings that it can be modified even after the code has been    deployed to the server without compiling the entire application again. 2) Since it is a XML file, there is no need of building the project of you are going to change the connection strings.   If you go for the class files,...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

How to connect PB .NET Web Forms to MS SQL 2005 via SNC using "Windows Authentication"?
Dear All, I have a PowerBuilder native client / server application which connects fine to the Microsoft SQL Server 2005 back-end database via the SNC native driver using "Windows Authentication" (NOT "SQL Server Authentication"). The corresponding program code being used is as shown below: ///////////////////////////////////////////////////////////////////////////////////////////////////////// String ls_userid, ls_password ls_userid = sle_id.Text ls_password = sle_password.Text IF Len(ls_userid) <> 0 AND Len(ls_password) <> 0 THEN // Pro...

How to deploy .Net Windows/Web applications
Hello can anyone please advise me guide me how to deploy .Net Windows/Web applications. I know how to do basic deployment but i want to know more about database connection string, Support files specific to application.   Please help--------ThanksSK Hi there,Database connections will not change too much, you will only need to change the Uid,password, server and sometimes database can also create a setup file which will setup all the things. check out these:

web.config having multilple connection string name with same connection.
Issue 1:   <add name="Conn1" connectionString="Data Source= SID;User Id=UN;Password=Pwd" providerName="Oracle.DataAccess.Client"/>  And use Conn1(Read and Write from DB)  All over the application. (for exam: all Data Access Layer). VersusIssue 2: <add name="Conn1" connectionString="Data Source= SID;User Id=UN;Password=Pwd" providerName="Oracle.DataAccess.Client"/> <add name="Conn2" connectionString="Data Source= SID ;User Id=UN;Password=Pwd" providerName="Or...

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

Get connection string from web.config and secure that connection
Hi, I store my connection string on my web.config file, and I want to create a new connection on c# like:SqlConnection con = new SqlConnection();con.ConnectionString= //connection string on web.config fileAfter that, The connection string on the web.config file is in clear text and I want to make it secure but easy to work because this job is to deliver until friday. Is there any easy way to do this and keep the possibility of creating a new connection and making reference to this connection string without need for decrypt data?Thanks, please help!Best regards,David Ribeiro After reading t...

Web resources about - Connection String not Initialized in Scheduled Task? -

Alexis Ohanian, Garry Tan, and Harj Taggar’s Initialized Capital Raises $39 Million
... based angel investors that has raised $39 million to invest in technology companies, according to VentureBeat . The joint fund is called Initialized ...

YC Partners Taggar, Tan And Reddit Co-Founder Ohanian Raise $39M For Initialized Capital
... the early-stage firm’s “Ambassador to the East” and Reddit co-founder Alexis Ohanian have raised $39 million for a separate fund called Initialized ...

App Store - Applause Karaoke - Rock Out to Your iTunes Library
Read reviews, get customer ratings, see screenshots, and learn more about Applause Karaoke - Rock Out to Your iTunes Library on the App Store. ...

Pseudonym - Wikipedia, the free encyclopedia
Pseudonyms are often used to hide an individual's real identity, as with writers' pen names , graffiti artists' tags, resistance fighters' or ...

Graphics Interchange Format - Wikipedia, the free encyclopedia
The Graphics Interchange Format ( GIF ; / ˈ dʒ ɪ f / or / ˈ ɡ ɪ f / ) is a bitmap image format that was introduced by CompuServe in 1987 and ...

Plus Products
PlusOptimizer, PlusMaker & PlusMaximizer Support PlusOptimizer and Mac OS X (including 10.4.x and later) PlusOptimizer will not optimize disks ...

Java - Moving Forward
Homepage of Andrew Robinson

Price Drop: Applause Karaoke
... speakers.Important Notes: ★ Create a Karaoke Playlist of your favorite songs and add the playlist to app upon launch. ★ Lyrics have to be initialized ...

iDentify 2 » F.A.Q.
iDentify 2, meta data tagger for iTunes compatible video files automatically retrieves information about your video based on the file name

Resources last updated: 12/15/2015 11:18:13 AM