Question

I have a Resource text file setupfile.txt I have added to my project, and I have a method that attempts to read it for a connection string like this:

public static string GetConnectionString()
{
    StreamReader rdr = new StreamReader(@"C:\Users..."); // this doesn't cause any errors
    StreamReader rdr = new StreamReader(Properties.Resources.setupfile); // this doesn't
    mySqlConnectionString = rdr.ReadToEnd();
    rdr.Close();
    return mySqlConnectionString;
}

As I said before, all the file contains is a connection string and 3 numbers:

server=localhost;database=dcim;uid=root;pwd=LlmD62jL;
1,10,2

However when I attempted to run a test to see if the file contained text, I got the excpetion:

System.ArgumentException: Illegal characters in path

I don't know what's going on?

Was it helpful?

Solution

StreamReader constructor expects the file path, not the file content. I guess you're passing file content as string that's why you get exception due to invalid chars in file(may be due to ;).

All you need is

mySqlConnectionString  = Properties.Resources.setupfile;

Also I strongly recommend you to use App.Config file for ConnectionString.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top