简体   繁体   English

C#LINQ-to-SQL-不使用存储过程更新表

[英]C# LINQ-to-SQL - not updating table with stored procedure

SOLVED 解决了

I have problems with Linq to SQL inserting/updating/deleting dataset from table with stored procedures. 我在使用存储过程从表中向SQL插入/更新/删除数据集的Linq遇到问题。

  1. I have checked data connections, points on the same table that has been created when adding connection 我检查了数据连接,添加连接时在同一表上创建了点
  2. I'm using Linq-to-Sql classes designer for managing behavior of sprocs for my tables (insert, update, delete) 我正在使用Linq-to-Sql类设计器来管理表的sproc行为(插入,更新,删除)
  3. I have same app created with different code style and everything works just fine but i can't include location change (when someone else installs app) in my .cs files, so I want to do it on "right way" and make it work for everyone. 我使用不同的代码样式创建了同一个应用程序,并且一切正常,但是我无法在.cs文件中包含位置更改(当其他人安装应用程序时),因此我想以“正确的方式”进行操作并使其正常工作为了每一个。
  4. using sql server 2012 and vs2010 使用SQL Server 2012和VS2010

Here is my problem. 这是我的问题。 this is included in form as reference for DataContext 包含在表单中作为DataContext的参考

private ZavrsniradDataContext poziv = new ZavrsniradDataContext();
//I've tried without private, and including this into methods where I'm  using it and nothing.

after I declare some variables for sending it to sproc I call sproc for altering the table.. 在声明一些变量以将其发送给sproc之后,我调用sproc来更改表。

poziv.p_IzmjenaMjesta(@ID, @Naziv, @PP, @IDZupanije);
poziv.SubmitChanges();

note: I'm sending ID number of the dataset I want to change, for comparison.. 注意:我正在发送要更改的数据集的ID号,以进行比较。

Alter proc [dbo].[p_IzmjenaMjesta]
@ID int,
@Naziv varchar(30),
@PP int,
@IDZupanije int
.
.
.
Update Mjesto 
SET Naziv= @Naziv, PostanskiPretinac = @PP, IDZupanije = @IDZupanije
WHERE ID = @ID;

After I call the sproc, my table is being refreshed, and all changes are visible. 调用该存储过程后,将刷新我的表,并且所有更改都可见。 But after a while, all changes dissapear. 但是过了一会儿,所有的变化都消失了。 I believe all my sprocs and functions are working properly, with my table, but somehow I'm doing something wrong. 我相信我的所有存储库和函数都可以在我的表上正常工作,但是以某种方式我做错了事。 everything works perfecrly when I run sprocs in Management studio. 当我在Management Studio中运行存储时,一切都会正常运行。

My other app contains this definition in beggining of the form, and everything works perfectly. 我的其他应用程序以表格的开头包含此定义,并且一切正常。 updateing, inserting, deleting! 更新,插入,删除! But i don't want that solution because then I have to create fixed location for my database on every PC. 但是我不想要该解决方案,因为那样的话,我必须在每台PC上为数据库创建固定位置。 I just want to install it and run it :) 我只想安装并运行它:)

public partial class Mjesta : Form
{
    ZavrsniRad poziv;

    public Mjesta()
    {
        InitializeComponent();
        poziv = new ZavrsniRad(@"c:\zavrsni_rad\Zavrsni rad.mdf");
    }

NOTE: I'm using exact copy of both databases on different locations with same sprocs/functions/dataset for different apps, and one is working, the other one is not working. 注意:我在不同位置使用两个数据库的精确副本,并且为不同的应用程序使用相同的存储过程/函数/数据集,一个正在运行,另一个在运行。 and that grinds my gears :( 那会磨我的齿轮:(

I have solved it. 我已经解决了。 app is running and working properly... I forgot on that little thing :( 应用正在运行并正常运行...我忘了那件事:(

Problem solver, add all rights on modifying your database to every account you have. 问题解决者,将修改数据库的所有权限添加到您拥有的每个帐户中。 That also includes rights to log file. 这还包括日志文件的权限。

(i dont have rep points for posting pics) http://www.pohrani.com/f/v/AQ/2bPLiVcP/slika.jpg (我没有发布照片的代表点) http://www.pohrani.com/f/v/AQ/2bPLiVcP/slika.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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