I have wanted to learn C# for some time now so I am taking the plunge and converting an existing MS Access DB (2007) and converting it over to C#. It really is more of a front end to run stored procedures and then generate Excel Workbooks all done with VBA. So not a full on database.
I am working on this line by line from my code.
I have created my form.
I created System Properties and added the data references to my project.
Now I am just working on getting my connection to the database and I am getting an error a field initializer cannot reference the nonstatic field method or property in connection string
I did a bunch of google searches but could not really figure it out. Something about my variables could be set to nothing before the string is created.
It is failing on the construction of ConnectionString where I have my variables.
Here is my code.
string myServer = Properties.Settings.Default.Server;
string mySQLServer = Properties.Settings.Default.SQLServer;
string myDatabase = Properties.Settings.Default.Database;
string myConnectionUser = Properties.Settings.Default.ConnectionUser;
string myPassword = Properties.Settings.Default.Password;
ADODB.Connection conn = new ADODB.Connection();
string ConnectionString = "Driver=SQL Server;Server=" + mySQLServer + ";Database=" + myDatabase + ";UID=" + myConnectionUser + ";PWD=" + myPassword + ";";