ASP.NET LINQ to SQL SubmitChanges() doesn't update the database - asp.net

In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I call the SubmitChanges method of the DataContext class, nothing updates in the database. It's weird because everything works fine with my first project.
I'm using a remote database created in Sql Server Management Studio, I tried doing some queries there and in Visual Studio 2010 (where I have the connection to the database), they all work.
Where might the problem be hidden?
DBDataContext DB = new DBDataContext();
var myuser = DB.Users.Single(u => u.ID == id);
myuser.Age = 45;
DB.SubmitChanges();
SOLUTION
This is embarrassing :D Indeed I didn't have a primary key. Now it works!
Thanks to everybody!

Table , KEY :)::):)
Insert KEY in TABLE !!!!!

Maybe there isn't anything to submit to the database? SubmitChanges() only will submit modified or new data, if you don't have either, then it will no have any persitent effect.
You may want to read ScottGu's series on Linq to understand a bit more about Linq, or could want to by a book like Linq in action.

Is it possible that the entities you are modifying are not connected to the DataContext? This would prevent them from causing updates to your database.

I'd check your connection string. You might not be connecting to the database you think you're connecting to.

Related

Entity Framework Core Scaffold - Dynamic Schema Name

I'm having an issue at the moment where, we have a database which was already created, so used ef scaffold to create a model of it - the schema the model was created against is called "xxxx-dev".
Now, this has been fine, but in preparation to go live, I created a new DB server and provisioned the database to be called "xxxx-live". Switched the connection string, and attempted a query against it, and got an error.
It seems that scaffolding has hard-coded the schema name into every table in the OnModelCreating call, for example:
modelBuilder.Entity<xxxx>(entity =>
{
...
entity.ToTable("xxxx", "xxxx-dev");
...
});
This is a bit of an issue as going forward, we might have multi-tenant sites based on the same database, and obviously the query overriding the connection string every query isn't a great experience.
Is there anyway to configure the schema name, either in the Scaffold, or at runtime? I've done a bit of searching around and can't seem to see a solution.
Thanks,

item reader in spring batch is not able to read a oracle table

Item reader in spring batch is able to read other tables But it is not able to read a table. But I am able to read it in sql developer. I am getting exception like reader initialization failed.
Can Someone help me on this?
I found the mistake i have done. The user which i am using in java to access db hasn't privilege for the table i am trying to access.. In SQL developer i am using the user which has privilege for all the tables.
Thanks a lot for your response and time.

FoxPro Database and asp.net

I have a website that uses asp.net 3.5 and Sql server 2008 as backend data store . now we want to add a new page to our website . but the data that we want to share in this page is already being created and saved by a FoxPro software in one of our local systems.
I've no experience in FoxPro . is there any way to use this data in our site ? specially without being have to create a new database in server and importing or writing all records all over again ? what is the best way in such a situation ?
by the way , is it possible to change the extension of a FoxPro database or not ? something like Database.customExt ?
You can connect to a FoxPro database using an OLEDB datasource in ADO.NET. It's up to you whether you feel the need to import the data into SQL Server or just access it directly in FoxPro. It would depend on whether you want to join the data with the SQL Server data in queries for one thing.
In addition to the answers that you already got. You might be interested in using LINQ to VFP or VFP Entity Framwork Provider to make the data access even easier by using LINQ.
You could create a linked server to this Foxpro Database.
Also, Foxpro tables can have any extension. However, you'll have to specify the extension when using the table or database. For Example:
OPEN DATABASE MyFoxProDatabase.customExt
USE mytable.custonExt
You have several options for structuring your data access to FoxPro. You can put the ADO.NET data access code in the codebehind, in it's own c# library or use the objectdatasource for 2 way binding.
private void LoadData(string parameter)
{
string sql = "SELECT a.myfield FROM mytable.customExt a WHERE a.whereField=?";
using(OleDbConnection conn = new OleDbConnection(myConnectionString))
{
using (OleDbCommand command = new OleDbCommand(sql, conn))
{
command.Parameters.AddWithValue("#Parameter", parameter);
try
{
conn.Open();
using(OleDbDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
{
myGridView.DataSource = dr;
myGridView.DataBind();
}
}
catch (Exception ex)
{
throw;
}
}
}
}
Here is a sample connection string to use in web.config:
<add name="myData" connectionString="Provider=VFPOLEDB.1;Data Source=C:\MyFiles\" providerName="System.Data.OleDb"/>
I belive ou can use a custom extension to your FoxPro tables and databases. All your SQL statements would then need to explicitly use that extension.
SELECT t.MyField FROM MyTable.customExt t
While you can change the extension for a Visual FoxPro table, that only affects the DBF file. If the table has any memo fields, there's an associated FPT file, for which you can't change the extension. Similarly, if the table has an associated index file, it must have a CDX extension.
So, if the reason you want to change the extension is to allow multiple tables with the same filestem, don't. It's a good way to really mess things up.

Can I solve this using oracle db listener?

Try to be more clear, I'm in lack of ideas in this problem, even it sounds like a classic.
My application is running on weblogic 10.3.3 application server, and for database I am using Oracle database 11g. My problem is that there is table in db, let's say "user.", there is column, let's say "columnA", in this table. This table is updating by some module of application.
What I want if when value of column is "abc.", then I have to show alert to console(IP). {IP can be retrieved from DB as it is configured in DB. this ip will be other linux system other than linux machine where oracle database is installed.} Updating is continuously done on my table from module of application. Please tell me from where should I start?, what should I read. I am not able to understand what should be approach. Any help is much appreciated.
Can u provide me any begginner.s link of oracle db listener?
You probably want to look at setting up a Trigger in the database
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/triggers.htm
An alternative to a trigger would be to log update queries against the table (to a log file) and have a process monitor the log, sending out alerts when something happens.

Deleting Database in Linq

In normal condition, I can add schemas in the dbml file to empty database with code below.
But now when I run this code, I take the error "Cannot drop database "test" because it is currently in use." How can I do it?
Dim db As New UI_Class.UIData
If db.DatabaseExists Then
db.DeleteDatabase()
End If
db.CreateDatabase()
It might happen as your SQL Server Management Studio (SSMS) must be holding it.
Most likely something is connected to the db.
Common causes are:
Some other tool connected
Trying to delete the database you connected to.
Another user connected to the db.

Resources