Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top