System.ArgumentException: Keyword not supported: 'datasource'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mannem
    New Member
    • Jan 2008
    • 9

    System.ArgumentException: Keyword not supported: 'datasource'

    Hi when iam trying to insert data into tables created in sql database iam getting this error
    could someone help me

    CODE:
    Code:
    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
            SqlDataAdapter da = new SqlDataAdapter("select * from Students", cn);
    web.config file
    [code=xml]
    <connectionStri ngs>
    <add name="connectio nstring"
    connectionStrin g="datasource=. \SQLEXPRESS;Att achDbFilename=| DataDirectory|D atabase.mdf;Int egratedSecurity =True;UserInsta nce=True"
    providerName="S ystem.Data.SqlC lient"/>
    </connectionStrin gs>
    [/code]
    Last edited by Plater; Jan 25 '08, 02:01 PM. Reason: adding [code] tags
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    But your code shows you are not inserting but selecting records from database tables.

    Comment

    • DrBunchman
      Recognized Expert Contributor
      • Jan 2008
      • 979

      #3
      Are you using the database on your local machine? If not using

      datasource=.\SQ LEXPRESS

      won't work. If you are using a remote machine you will need to use

      server=ServerNa me\SQLExpress

      instead. Does this help?

      Dr B

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Have you checked here:
        404 - Page Not Found. Shown when a URL cannot be mapped to any kind of resource.

        Comment

        • mannem
          New Member
          • Jan 2008
          • 9

          #5
          Originally posted by debasisdas
          But your code shows you are not inserting but selecting records from database tables.
          This is my actual code
          string cs;
          cs = ConfigurationMa nager.Connectio nStrings["ConnectionStri ng"].ConnectionStri ng;
          SqlConnection cn = new SqlConnection(c s);
          SqlDataAdapter da = new SqlDataAdapter( "select * from UserInfo", cn);
          SqlCommandBuild er cmb = new SqlCommandBuild er(da);
          DataSet ds = new DataSet();
          da.Fill(ds,"Use rInfo");
          DataRow row;
          row = ds.Tables[0].NewRow();
          row[0]=User.Identity. Name;
          row[1] = txtstreet.Text;
          row[2] = txtcity.Text;
          row[3] = txtstate.Text;
          row[4] = txtcountry.Text ;
          row[5] = txtpin.Text;
          row[6] = "./../Images/" + fileupload1.Fil eName;
          ds.Tables[0].Rows.Add(row);
          da.Update(ds.Ta bles[0]);
          fileupload1.Sav eAs(Server.MapP ath("./Images/" + fileupload1.Fil eName));

          In web.config

          <connectionStri ngs>
          <add name="connectio nstring"
          connectionStrin g="datasource=. \SQLEXPRESS;Att achDbFilename=| DataDirectory|\ onlineexam.mdf; IntegratedSecur ity=True;UserIn stance=True"
          providerName="S ystem.Data.SqlC lient"/>
          </connectionStrin gs>

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            EDIT: Ok I got it now:

            Using an User Instance on a local SQL Server Express instance
            The User Instance functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer.
            Code:
            Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;
            Data source is two words, not one.

            Comment

            • mannem
              New Member
              • Jan 2008
              • 9

              #7
              Originally posted by DrBunchman
              Are you using the database on your local machine? If not using

              datasource=.\SQ LEXPRESS

              won't work. If you are using a remote machine you will need to use

              server=ServerNa me\SQLExpress

              instead. Does this help?

              Dr B
              Hi
              iam using local machine only

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Originally posted by mannem
                Hi
                iam using local machine only
                datasource should be "Data Source"

                Comment

                • mannem
                  New Member
                  • Jan 2008
                  • 9

                  #9
                  Originally posted by Plater
                  EDIT: Ok I got it now:


                  Code:
                  Data Source=.\SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|\mydb.mdf;User Instance=true;
                  Data source is two words, not one.
                  Thank you very much
                  its working
                  great

                  Comment

                  • mannem
                    New Member
                    • Jan 2008
                    • 9

                    #10
                    Error

                    Iam getting this error

                    Violation of PRIMARY KEY constraint 'PK_UserInfo'. Cannot insert duplicate key in object 'dbo.UserInfo'.
                    The statement has been terminated.

                    when i try to register a new user it always takes the server name for every user and giving this error
                    iam using Registercontrol for registering new users and to retrieving and storing the username iam using User.Identity.N ame which is the primary key in my table.
                    help me
                    Last edited by mannem; Jan 25 '08, 03:50 PM. Reason: to add more details

                    Comment

                    • ujean
                      New Member
                      • Dec 2014
                      • 1

                      #11
                      I had the same error, for what it's worth mine was caused by something different so I hope this helps someone:
                      1. EDMX error: first there was a new database table in the EDMX and the table did not exist on my database. Funny thing is the error the error was not very obvious because it was not shown in my EDMX, instead it was tucked away in visual studio in the 'Error List' window under the 'Warnings'. After I sorted it by adding the missing table to my database I still got a 'datasource' error but since I was busy trying to add a stored procedure I thought there was something wrong with the proc, see the next line.
                      2. Stored procedure error: I was trying to add a stored procedure and everytime I added it via the EDMX design window I got a 'datasource' error. The solution was to add the stored procedure as blank (I deleted the contents of the stored proc and replaced it with 'select 1'). It worked! Presumably EF didn't like something inside my proc. Once I'd added the proc to EF I then updated the contents of the proc to what I wanted it to be and it works, 'datasource' error resolved.


                      weirdness

                      Comment

                      Working...