"Invalid attempt to read when no data is present" - why? - c#

I'm getting the error mentioned in my subject line and I don't know why. I have an ADO.net entity and a domain service class and am doing this as I have read in tutorials and what not. Also you should bear in mind that it worked fine up until today, and so far as I know I didn't make any changes.
The database exists and the table is there as it always was. I suppose it's possible someone could have changed the table, but there are still entries (and they seem to be the same as before, but I couldn't guarantee that).
I am still connected to that source and it's not changed IP (I can remote desktop onto the server to see the SQL Server Management Studio).
If you want to ask what changes I made... not really any. I added a drop down box on my page which tells the user when database access is happening and after it finished, but then removing that still left me with this same problem so I rather think it's unrelated. I have searched Google, but none of the solutions seem to be for Silverlight.
Thanks, and I hope someone can shed some light here.

Related

SQL Server table.Script() method throwing strange exception

I have a server with a database on it that I can access through SSMS and I am an owner of. Meanwhile in C#, I create an instance of Microsoft.SqlServer.Management.Smo.Table which inherits from Microsoft.SqlServer.Management.Smo.TableViewTypeBase.
TableViewTypeBase has a method called Script(), and as you can see from the link there, the documentation isn't exactly illuminating.
Here's what I'm trying to do: I connect to the server successfully and to the database successfully. I can get a list (or something like a list, a collection maybe) of tables in the database via database.Tables. Then I grab a specific table from those Tables and I want to call that Script() method on it.
As you might already guess, this isn't code I have written but I'm here now trying to get it to work. For a lot of the tables I've done this with, there are no issues. However, with one of them, I'm getting this error:
Script failed for Table X
Googling for this leads to a lot of answers about "publications" and "subscriptions" that I don't think apply to my situation, but I'm quickly getting out of my depth. This link from MSDN says I need to update my "database compatibility level"?
Soooo of course I head on back to Google and find this link from the Microsoft Docs, and all is going well until I get to Step 5 and wouldn't you know it—that dropdown is grayed right out. No number is shown there. It looks like this:
And I'm pretty sure it's not a permissions issue because I'm an owner of that database!
So, wise ones: what do you recommend? There just aren't that many answers out there for this particular error and the documentation is basically nothing. I'm running out of ideas.

"Row not found or changed" when updating value of single attribute, but only for SOME rows

Okay I will try to make this pretty brief. I have done a lot of searching the last 1-2 days and I can't find an answer to my problem so I will try to narrow it down. The most common cause of "row not found or changed" in LINQ/SQL appears to be a schema discrepancy between the database and the .dbml file (based on both my research and my personal experience). The database I'm working with is too complex for it to be worth sharing the full schema, so I just want to ask one main "hypothetical" question:
If the "Row not found or changed" error only occurs for SOME rows, despite them all having the exact same operation done on them, is it still possible that it could be an issue with .dbml discrepancies (nullable/non-nullable, data types being wrong, etc)?
I feel like if there was a normal schema issue in the .dbml file, it wouldn't let me update ANY rows in the table, but in this case it lets me update most of them without an error.
My guess right now, which I am about to investigate, is that it may be failing when the row is connected to another table via a foreign key and that table has an issue in the .dbml, but I wanted to post this question now because I have put a lot of hours into this issue and would like to resolve it pretty soon, so maybe there is a stupid reason that I'm unaware of.
Thanks for any help. I shouldn't really need help with this because it's kinda stupid, but I'm really frustrated

Connection Strings in local exe.config removed (using EF)

Imprtant note: this is only happening on clients, not in dev environment
I'm having an odd issue. An application I have written / deployed at my company uses 3 connection strings within it to query data from various sources as needed. Every so often, I get an error report from one of the end users machines stating something like
System.InvalidOperationException
No connection string named 'CM_PS1Context' could be found in the application config file.
So, I went to this machine, opened up the exe.config file, and sure enough, 2 of the connection string entries were just.... gone. I went to my machine, grabbed the entries from my config, dropped them in, everything was working again.
I can't make heads or tails of this, nothing in my code is modifying the app.config (user.config, yes). I am using EntityFramework for all 3 databases. Has anyone seen this, or maybe has an idea of what might be happening?
Note, this is not happening to all clients, it seems very very random at the moment, as I am unable to reproduce the error myself (nor can anyone if they are trying)
For the moment, my fix is going to be something retarded like watching for that error and when it occurs, reinsert the connection string, but... that's a very messy, ugly fix, that I'd prefer NOT to put in production. Any suggestions would be very helpful!

ASP.NET with EF 4 getting incorrect data from SQL Server database

I updated my ASP.NET site from Linq-to-SQL to EF 4. I've had a bunch of hiccups along the way but have ironed most out.
Not sure if it has anything to do with EF but recently my application has started going nuts at random times. I'll delete one or multiple records from my SQL Server database, but when I re-display the page that was listing those records they're still there. I check my database and the records are gone yet when my code queries for this data after it's deleted my data model is still getting that deleted data and displaying it on my site. The only way I've found to get around the issue is closing the web browser or stopping my local host when debugging. Obviously not the fix I want. It happens on server code and local host.
This problem is very rare and difficult to reproduce and it only happens some days but not most days. I'd like to say it's completely random but I know there has to be some variable and I can't figure it out. Any suggestions?

have some Database questions (creating, connecting, security... etc)

i am quite new in programming, and have few questions regarding in play with the database...
(sorry if i make my post bit long)
I learn to work with Visual Studio 2008 using C#
1. How to create the database? - is there a correct way for always?
How i learned to do it:
- In the Solution Explorer i right click and then go to Add -> New Item... -> (select) Service-based Database -> (click) Add -> Finish. and that is all. Then in Solution Explorer i go in app.config and from there i can find the connection string that later on i can use it, and it looks like this:
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
So is this the correct way to create a database? Later on as i tested, i would need to install SQL Express to the computer that doesnt have visual studio in order this database could work for the program..
So is there better ways in creating a database, or this is just fine..
2. How to secure the database from others to open it?
With this i mean, someone else in visual studio might also open the tables and records and everything that is in the database. Simpy by just creating a new project, right clicking on "Server Explorer" window then "Add connection" as a data source to choose "Microsoft SQL Server Database File" then simply to browse the existing database. And after that, you have full access on the database. So any tips about this?
3. How to create a database programmatically?
So my idea here is that in the future i might want to create a new database that a program would use (that already is connected to another database). But have no idea on how i would use that connection string (how to get it), if the database is made using code (a button is clicked by the client for example to create a new database for a new "working year"). I have tried few from the examples i found on the internet for creating a database, but it always trows me an error...
I know that this questions are not specific, but i am new in programming and am bit unsure if i am doing the right way, and i know this place isn't like a forum, but i thought i might get some good answer that would guide me towards building my future knowledge...
P.S. I am quite young, and sorry if i made some mistakes in the writing (english is not my main language)...
(and if i was not clear in some way, please tell me and i ll try to be more clear)
How to create the database? - is there a correct way for always?
For, small student projects it might be fine but in long run you will have to learn DBMS and Database design techniques. Some known databases are MS SQL, MySQL, Oracle, DB2 etc. Since you are working with Visual studio so i will suggest that you should install MS SQL free edition.
The more you start working with the latest technologies, the more ways you will find to create a database. Latest technologies add some sort of abstraction, so initially, just focus on creating a database in DBMS.
How to secure the database from others to open it?
Well, you need some sort of book to understand the database first.
In real world scenario's, mostly, the database is on a secured server and only database administrators have rights to change things in it. Developers usually have read only rights and they request the admins to run scripts the database. Secondly, the database that the developers get is usually encrypted i mean clients almost never give real data to the developers for security point of view.
Lastly, if you are using MS SQL then your database is always behind some sort of security like the Login box initially.
How to create a database programmatically?
Well, there are ways but since you are new you should try them for now. Post your problem here, and people will guide you with some easy way to achieve your task.
In the end, forums are great way to learn things. I do the same by asking questions to seniors. Keep it up and welcome to SO and programming, you will enjoy this community.
Welcome to SO. As written in comment you need to start with a good book, I an sure you can something online.
One suggestion is to always first check Google. For example, searching for your third question brings up several results, and going through even the first couple will give you all the information you need.
When you have a specific question, ask here along with some code showing what you have tried and make your best attempt creating an SSCCE. I assure you the answers will be quick.
1. How to create the database? - is there a correct way for always?
There is no correct way for always for anything. Most software create database programmatically, since you cannot expect your users to create the correct schema for you. This is typically either done in an installer or at start up.
2. How to secure the database from others to open it?
There isn't any easy solution to this. One option is to ask the user for a password when creating the database and then again the ask the user every time they run the program. Some databases allow creating an encrypted properties files for starting the database server specifying a password.
In general, security is a very big topic. Again, a google search brings up interesting material but with less definitive guidelines
3. How to create a database programmatically?
Check Google. This is a specific question but you should be able to find out the answer for yourself quite easily.

Categories

Resources