Results 1 to 3 of 3

Thread: connection string for sqlexpress ,stumpted

  1. #1

    Thread Starter
    Lively Member mikelynch's Avatar
    Join Date
    May 2006
    Location
    Goombungee Qld
    Posts
    83

    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");
            }

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. SqlConnection thisConnection = new SqlConnection(string.Format(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0}\GymData3.mdf;Integrated Security=TrueUser Instance=True",
    2.                                                                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)));
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    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
  •  



Click Here to Expand Forum to Full Width