I found this article for the majority of the code here How to set SQL Server connection string?.
Here's what I have though:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(localdb)\\Instance;" +
"Initial Catalog=Database;" +
"User id=root;Password=pass;";
try
{
conn.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
SqlCommand myCommand = new SqlCommand("INSERT INTO Database.dbo.Table" +
"VALUES ('stg', 'stg1', 'stg2', 'stg3');", conn);
try
{
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
A lot of the previous code was giving me errors. At one point, I was getting an error that I couldn't connect to the instance. This was an issue with the '\'. It was recognizing it as an escape character, so I did double '\' to get rid of that, so I'm not getting that error anymore, so that shouldn't be the problem.
I was getting an error about the wrong username and password. I'm using SQL Server Authentication and the code I was previously using was specifying Windows authentication. I'm not getting that error anymore.
As of right now, the code executes all the way through with no errors. When I check on the database though (I'm using SQL Server Management Studio), nothing gets inserted into the table. I have ran the Insert statement directly and it works fine, so I'm not sure what the issue is here. Also, I'm using VS 2013.