简体   繁体   中英

connect to .mdf file in vs2010 , wpf application

I am using VS2010 , and I built a .mdf file using SQL server 2008

I want to use this database file in my wpf application so that I can add rows to it and delete rows from it

the problem is , I can't access this file , and all the insertion and deleting is actually hapening to the datacontexct i created .

I used myDataContexct.Submitchanges() but it didn't work either

I tried to add a connection string when I define the datacontexct that holds the url of my .mdf file and this it gave me a runtime error when trying to access this file and the error messege says :

An attempt to attach an auto-named database for file Trial.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

please help me because I searched alot but I couldn't find any help

  1. If the application is not going to be installed in a manner that many clients are accessing the same server, you would want to consider using SQL Server Compact Edition.
  2. Are you sure the connection string in your app.config refers to the local mdf file? perhaps it refers to the server instance?
  3. What technology do you use, is it LinqToSql or Entity Framework (I think you have t call SaveChanges , not AcceptChanges )?
  4. If you do intend to access the server instance, then the problem seems to be a security restriction.

Please add more details on statement no. 1, and I'll write further info.

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