0

I have a SQL Server 2008 Express edition database and I am inserting data to it via a windows application, using Linq-to-SQL. I know the data exists in database because when I query the database I get some data but in SQL Server Management Studio when I right click on a table and click even : 'Edit top 200 rows' or 'Select top 1000 rows' I can not view any data ! any helps ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
gwt
  • 2,331
  • 4
  • 37
  • 59

2 Answers2

2

Assuming you're using the User Instance and AttachDbFileName= approach - I would argue this approach is severely flawed. Visual Studio will be copying around the .mdf file and most likely, your INSERT works just fine - but you're just looking at the wrong .mdf file in the end!

If you want to stick with this approach, then try putting a breakpoint on the myConnection.Close() call - and then inspect the .mdf file with SQL Server Mgmt Studio Express - I'm almost certain your data is there.

The real solution in my opinion would be to

  1. install SQL Server Express (and you've already done that anyway)

  2. install SQL Server Management Studio Express

  3. create your database in SSMS Express, give it a logical name (e.g. VictoryDatabase)

  4. connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:

    Data Source=.\\SQLEXPRESS;Database=VictoryDatabase;Integrated Security=True
    

    and everything else is exactly the same as before...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
1

I believe LinqToSql has a "Save" command that actually writes the data to the database. Until that happens you are merely holding it in memory.

ETA: see this question and its answers

Community
  • 1
  • 1
Ann L.
  • 13,760
  • 5
  • 35
  • 66