Tag: c#

Lock database, using C#

I use C#, EF and Microsoft SQL Server in my project. I need to lock the whole database on one of the machine to synchronize it with Active Directory. Many machines have access to the database, so I need to prevent reading, inserting or updating my database from another machines. Simple example, what I try […]

Executing ToList multiple times in IQueryable

I am trying to fine tune some of the EF code. I could see, that one Iqueryable is converted to list multiple times. Does it mean, EF will execute the query as many times the tolist is invoked (or) will it just execute the query once and will return the same results for the rest […]

Listing only the last version of a row in a composite key

I’m having a little bit of trouble understanding how composite keys are supposed to work with Entity Framework or SQL in general. This is how my table looks like: COD_ITEM COD_ITEM_VERSION ITEM_NAME 1 1 A 1 2 A 1 3 A 2 1 A 2 2 A 2 3 A 2 4 A 2 5 […]

Update Each Exisiting Row of SQL Server Table Using Loop

I’m trying to update a certain column for each row in my SQL Server table, using ASP.NET, C#. When this code is executed, I want the OrderNo of the first row in the column to be = 1. From then on, I want the OrderNo to increment by 1 for the other existing rows in […]

SQL Server can't find my function in my DLL / Assembly

I created a library class in C# with this code as you can see: namespace ManagedCodeAndSQLServer { public class BaseFunctionClass { public BaseFunctionClass() { } [SqlProcedure] public static void GetMessage(SqlString strName, out SqlString strMessge) { strMessge = “Welcome,” + strName + “, ” + “your code is getting executed under CLR !”; } } } […]

DISTINCT query not working its give me repeated columns on output

Buddy i have one query of MSSQL. that is like this.. SELECT DISTINCT resource.locationurl, resource.resourcename, resource.anwserid, checktotal.total FROM resource INNER JOIN (SELECT Count(DISTINCT anwserid) AS total, resourcename FROM resource AS Resource_1 WHERE ( anwserid IN (SELECT Cast(value AS INT) AS Expr1 FROM dbo.Udf_split(@sCategoryID, ‘,’) AS udf_Split_1) ) GROUP BY resourcename) AS checktotal ON resource.resourcename = […]

How to update foreign key in EF 6 – Code First – One to many relationship

Based on the solution provided in this question : How to update foreign key in EF 6 – Code First, I’m able to update my foreign key using the id field. But now, I get an exception when getting entities from the database. Using this code : // Retrieve data first using (var db = […]

Proper way to null check in Expression-Tree lambda

First of all, I want to excuse myself for posting a similar question to other existing ones, but I am new to C#, and only starting to grasp LINQ. I have some business logic across two tables that gets a field of a row. If no such row exists, it should just default to an […]

Copying Data from Oracle Server to SQL Server

I’m quite new to coding in general and I’m looking to copy 47 columns with c300,000 rows of data, from an Oracle to an SQL database, on a daily basis. The code will be stored as a Windows Service, running at the same time every day (or more likely night). The data from the Oracle […]

Which way is correct to connect to SQL Server for transaction

Which way is more correct to delete entity? Correct means: for a lot of rows, we should use way that is more trust-able and close transaction after end of work First attempt: public class UserRepository : IDisposable { private DomainModels.BotEntities _dbDnt = null; public UserRepository() { _dbDnt = new DomainModels.IraniBotEntities(); } public bool Delete(int id, […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.