UPDATE 2
I fixed the error by adding System.Configuration
to the reference file. I had already added it to my class with using System.Configuration;
I found the answer here: The name 'ConfigurationManager' does not exist in the current context
Any further issues will be addressed in a new question.
Original(ish) Post
I have Microsoft SQL Server Management Studio. In the studio I created a database called Logbook
that exists locally on my computer.
I have also created a user interface using a Windows forms application in VS C# Express. I would like to connect it to my logbook database in order to update, select, delete, and insert entries into the database through the UI.
However, I cannot figure out how connect the two. I have played around with the "Add new data source" wizard to no avail. I also cannot find anything helpful in the MSDN or other tutorials online.
UPDATE
I created a new database and project to work with until I figure out how to properly do this so I don't accidently break anything in my project.
The Schema is:
Student(sid: int, fname: char(10), lname: char(10), age:int, major:char(10))
Course(cid:int, desc:char(50), dept:char(10))
Enrolled(sid:int, cid:int, quarter:char(10), grade:char(10))
Here is the connection string generated by the "Add Data Source" wizard
<add name="boathouseLogConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\boathouseLog.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
I have successfully gotten my database into the project. However, when I try running a stored procedure I get this error Argument Exception was unhandled. Format of the initialization string does not conform to specification starting at index 0.
The error occurs on line 2.
DataTable dt = new DataTable();
SqlConnection sqlConn = new SqlConnection(selectedConnectionString);
SqlCommand myCommand = new SqlCommand("proc_getMember", sqlConn);
myCommand.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(myCommand);
the selectedConnectionString
variable is set to boathouseLogConnectionString