connection string for sqlexpress ,stumpted
I am getting "keyword not supported" for my connection string. I have tried to edit it a lot but getting nowhere.
Please help me with the connection string
Code:
using System.Data.SqlClient;
namespace Gymdata4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection thisConnection = new SqlConnection( "Data Source=.\\SQLEXPRESS;AttachDbFilename=""+"C:\\Documents and Settings\\Michael\\My Documents\\GymData3.mdf""+"Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT * FROM customers", thisConnection);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
DataSet thisDataSet = new DataSet();
thisAdapter.Fill(thisDataSet, "customers");
}
Re: connection string for sqlexpress ,stumpted
Firstly I'd suggest usiong a verbatim string literal so you don't have to double-up your slashes.
Secondly, if you want to access a database in the current user's My Documents folder then I suggest that you don't hard-code it:
C# Code:
SqlConnection thisConnection = new SqlConnection(string.Format(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0}\GymData3.mdf;Integrated Security=TrueUser Instance=True",
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)));
Re: connection string for sqlexpress ,stumpted