简体   繁体   中英

Wp7 dataconnectivity exception

i have written a code to map a table emp contain fields empId empName Salary. but it throws an exception invalid application session id at button1 click as it reaches the for loop. need help to rectify it . i want to view the empId of a Empname = ss

private const string ConnectionString = "isostore:/Emp1.sdf";

    [Table(Name = "Emp")]
    public class Emp2
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int EmpId
        {
            get;
            set;
        }
        [Column]
        public string EmpName
        {
            get;
            set;
        }
        [Column]
        public int Salary
        {
            get;
            set;
        }
    }


    public MainPage()
    {
        InitializeComponent();

        using (CountryDataContext context = new CountryDataContext(ConnectionString))
        {

            if (!context.DatabaseExists())
            {

                context.CreateDatabase();

            }
            else
            {
                MessageBox.Show("Employee table exist already");
            }
        }




    }


    private IList<Emp2> getcountry()
    {
        IList<Emp2> countryList = null;
        using (CountryDataContext context = new CountryDataContext(ConnectionString))
        {
            IQueryable<Emp2> query = from c in context.Emp where c.EmpName=="ss"   select c;
            countryList = query.ToList();
        }

        return countryList;
    }



    public class CountryDataContext : DataContext
    {
        public CountryDataContext(string connectionString)
            : base(connectionString)
        {

        }
        public Table<Emp2> Emp
        {
            get
            {
                return this.GetTable<Emp2>();
            }
        }


    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        IList<Emp2> emp= this.getcountry();

        try
        {
            foreach (Emp2 a in emp)
            {
                MessageBox.Show(a.EmpId.ToString());

            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }


    }

Could it be that you are using wp7explorer? I had a similar issue and disabling wp7explorer solved the issue.

For more information, check out this link: http://wp7explorer.codeplex.com/workitem/8259

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM