Click here to Skip to main content
15,920,217 members
Home / Discussions / C#
   

C#

 
GeneralChild Control Painting problem(For the last time) Pin
Jon_Slaughter13-Jul-04 13:54
Jon_Slaughter13-Jul-04 13:54 
GeneralRe: Child Control Painting problem(For the last time) Pin
Heath Stewart14-Jul-04 4:12
protectorHeath Stewart14-Jul-04 4:12 
GeneralRe: Child Control Painting problem(For the last time) Pin
Jon_Slaughter14-Jul-04 5:28
Jon_Slaughter14-Jul-04 5:28 
GeneralRe: Child Control Painting problem(For the last time) Pin
Heath Stewart14-Jul-04 6:01
protectorHeath Stewart14-Jul-04 6:01 
GeneralBigger ImageList Pin
blankg13-Jul-04 11:50
blankg13-Jul-04 11:50 
GeneralRe: Bigger ImageList Pin
Heath Stewart14-Jul-04 4:01
protectorHeath Stewart14-Jul-04 4:01 
Generaldisable network card throw c# Pin
vipervip13-Jul-04 11:06
vipervip13-Jul-04 11:06 
Generalconfig file in console app to store connection string help Pin
mtbjr13-Jul-04 10:25
mtbjr13-Jul-04 10:25 
My console project is named UsingConfigSettings in C#, and wanted to store the database connection in an application config file. I added an application config named "UsingConfigSettings.exe.config" in my project. Here is its contents:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="constring" value="server=localhost;database=Northwind;uid=sa;pwd=;"/>
</appSettings>
</configuration>

I even copied it in the bin\debug folder in my C# console application, but it still doesn't work. I acccess it in the console as:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public class UsingConfigSettings
{
public static void Main()
{
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["constring"]);

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM Customers";
cmd.Connection = con;

con.Open();
SqlDataReader reader = cmd.ExecuteReader();

while(reader.Read())
{
Console.WriteLine("{0} - {1}", reader.GetString(0), reader.GetString(1));
}

con.Close();

Console.ReadLine();
}

}

but it won't work, it always issued a message of:

"An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: The ConnectionString property has not been initialized."

If I don't use any config file, and replace the code above, it works fine:

SqlConnection con = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");

Please help.
GeneralRe: config file in console app to store connection string help Pin
Heath Stewart14-Jul-04 3:56
protectorHeath Stewart14-Jul-04 3:56 
GeneralPointers and dereferencing Pin
frank29713-Jul-04 8:01
frank29713-Jul-04 8:01 
GeneralRe: Pointers and dereferencing Pin
Heath Stewart13-Jul-04 8:34
protectorHeath Stewart13-Jul-04 8:34 
Generalcapturing events when application closes Pin
vista2713-Jul-04 7:59
vista2713-Jul-04 7:59 
GeneralRe: capturing events when application closes Pin
Heath Stewart13-Jul-04 9:07
protectorHeath Stewart13-Jul-04 9:07 
GeneralArray of Struct within Struct Pin
Uday Shastri13-Jul-04 7:58
Uday Shastri13-Jul-04 7:58 
GeneralRe: Array of Struct within Struct Pin
Heath Stewart13-Jul-04 9:21
protectorHeath Stewart13-Jul-04 9:21 
GeneralRe: Array of Struct within Struct Pin
Uday Shastri13-Jul-04 9:47
Uday Shastri13-Jul-04 9:47 
GeneralRe: Array of Struct within Struct Pin
Heath Stewart13-Jul-04 10:19
protectorHeath Stewart13-Jul-04 10:19 
Generalupload files Pin
Steven M Hunt13-Jul-04 7:03
Steven M Hunt13-Jul-04 7:03 
GeneralRe: upload files Pin
Heath Stewart13-Jul-04 9:17
protectorHeath Stewart13-Jul-04 9:17 
GeneralRe: upload files Pin
Steven M Hunt14-Jul-04 14:31
Steven M Hunt14-Jul-04 14:31 
GeneralRe: upload files Pin
Heath Stewart19-Jul-04 2:02
protectorHeath Stewart19-Jul-04 2:02 
Generalstruct question Pin
ConfusedAsHeck13-Jul-04 5:30
sussConfusedAsHeck13-Jul-04 5:30 
GeneralRe: struct question Pin
Tom Larsen13-Jul-04 5:34
Tom Larsen13-Jul-04 5:34 
GeneralRe: struct question Pin
Heath Stewart13-Jul-04 6:11
protectorHeath Stewart13-Jul-04 6:11 
GeneralAccessing Forms Pin
Mehbub13-Jul-04 5:02
Mehbub13-Jul-04 5:02 

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.