|
-
Aug 21st, 2007, 02:11 AM
#1
Thread Starter
Lively Member
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");
}
-
Aug 21st, 2007, 02:42 AM
#2
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)));
-
Aug 28th, 2007, 12:19 PM
#3
Re: connection string for sqlexpress ,stumpted
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|