When you have DBML lINQ entity fields with CHAR data type. you will get an error while retrieve the data.
Solution:
----------
1) go to the DBML entity
2) select field
3) press F4
4) change data type to string from char, where you have DB data type VARCHAR(1)
5) Save
Tuesday, June 22, 2010
Wednesday, May 26, 2010
Cannot add an entity with a key that is already in use, LINQ
When you have table with ID coulumn (uniqueidentifier) and default value = (newid()),
than the above error occur.
To Resolve:
1) go to your .DBML file design view
2) go to property of particular columns
3) set "Auto generated Value" = true.
it will add following in DBML file IsDbGenerated="true"
than the above error occur.
To Resolve:
1) go to your .DBML file design view
2) go to property of particular columns
3) set "Auto generated Value" = true.
it will add following in DBML file IsDbGenerated="true"
Friday, May 14, 2010
Power shell, installutil
Error occur while installing powershell dll.
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information
Resolution:
make sure you have all the project reference dll in the project, developer always forgot reference dll while delpoying the project.
alternate approch is to load the reference DLL into GAC
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information
Resolution:
make sure you have all the project reference dll in the project, developer always forgot reference dll while delpoying the project.
alternate approch is to load the reference DLL into GAC
String or Binary Data Would Be Truncated Error, LINQ
Error: String or Binary Data Would Be Truncated.
Desc:
Generally this error occurs when we are trying to inser/update large value in SQL server table that are not fit into columns lenght of table.
In one scenario i experienced the following scenario:
I had the one enum like below:
public enum MyEnum
{ First = 101, Second=102, Sixth=103)
now I was using this enum like MyEnum.First and assigning to the one variable
But when i was trying to insert that entity in database using LINQ i was getting the above error:
After doing debugging, I've to do following changes
var myvar = (int) MyEnum.First;
The above statement will return the 101,
that's it for now.
Desc:
Generally this error occurs when we are trying to inser/update large value in SQL server table that are not fit into columns lenght of table.
In one scenario i experienced the following scenario:
I had the one enum like below:
public enum MyEnum
{ First = 101, Second=102, Sixth=103)
now I was using this enum like MyEnum.First and assigning to the one variable
But when i was trying to insert that entity in database using LINQ i was getting the above error:
After doing debugging, I've to do following changes
var myvar = (int) MyEnum.First;
The above statement will return the 101,
that's it for now.
object reference not set to an instance of an object C#
Error: object reference not set to an instance of an object
C# developer usually getting the above error, I'd suggeste first check where you are using Trim(), Substring(), Length(), ToUpper(), ToLower() function with string variables in your codind.
To Resolve:
if(!String.IsNullOrEmpty(userFirstName))
{
-- your userFirstName assignment code here
}
C# developer usually getting the above error, I'd suggeste first check where you are using Trim(), Substring(), Length(), ToUpper(), ToLower() function with string variables in your codind.
To Resolve:
if(!String.IsNullOrEmpty(userFirstName))
{
-- your userFirstName assignment code here
}
Saturday, April 10, 2010
common table expression (CTE) vs Cursor in SQL
----------about CTE------------
http://msdn.microsoft.com/en-us/library/ms190766.aspx
----------about CTE------------
Something to be aware of:
Cursors and temp tables are stored in tempdb.
CTEs and derived tables, if there is enough memory, are stored in memory. If they require more storage than is available in memory, they will use space within tempdb.
Views, if they use aggregate functions or are dealing with large volumes of data, may also touch tempdb.
This is important to consider when looking at performance. Operations that take place in memory are much faster. As soon as you have to touch spinning disk, things slow down. You also have to consider file placement (is tempdb on the same spinning disk as something else? Are tempdb's data and log files on the same spinning disk as something else?), disk controllers (including iSCSI NICs) and other sources of I/O contention.
As mentioned above, cursors allow you to access data in a result-set on a row-by-row basis.
Here's a design pattern I like to use:
Load a result set into a table-typed variable. Either use a candidate key or a surrogate key (provided by ROW_NUMBER() OVER () ) to loop through the table. With smaller sets, it can be MUCH faster than using a cursor.
For an example using a candidate key from within the resultset, instead of deriving a candidate key from ROW_NUMBER, just use test_data.id to identify a row.
Sorry about the lack of intentation... linkedin strips out leading spaces and tabs.
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'test_data')
DROP TABLE test_data
GO
CREATE TABLE test_data (column_1 nvarchar(255), column_2 nvarchar(255)
GO
INSERT INTO test_data (column_1, column_2)
VALUES
('1', 'one'),
('2', 'two'),
('3', 'three')
('4', 'four')
DECLARE @results TABLE
(
row_id int,
column_1 nvarchar(255),
column_2 nvarchar(255)
)
-- load up @results with only those rows where column_2 starts with 't'
INSERT INTO @results (id, column_1, column_2)
SELECT
ROW_NUMBER() OVER(ORDER BY column_1),
column_1,
column_2
FROM
test_data
WHERE
UPPER(LEFT(column_2, 1)) = 'T'
/* since row_id is a candidate key for @results, use it as a bookmark. */
DECLARE @current_row int
DECLARE @current_column_1 nvarchar(255)
DECLARE @current_column_2 nvarchar(255)
SELECT @current_row = MIN(id) FROM @results
WHILE @current_row IS NOT NULL
BEGIN
SELECT @current_column_1 = column_1, @current_column_2
FROM @results
WHERE id = @current_row
PRINT 'Current Row ID:' + CHAR(9) + CAST(@current_row as varchar)
PRINT 'Current Column_1:' + CHAR(9) + @current_column_1
PRINT 'Current Column_2':' + CHAR(9) + @current_column_2
-- get the next id value and start the loop again.
-- If there are no more rows, @current_row will be NULL,
-- thus exiting the loop
SELECT @current_row = MIN(id)
FROM @results
WHERE id > @current_row
END
http://msdn.microsoft.com/en-us/library/ms190766.aspx
----------about CTE------------
Something to be aware of:
Cursors and temp tables are stored in tempdb.
CTEs and derived tables, if there is enough memory, are stored in memory. If they require more storage than is available in memory, they will use space within tempdb.
Views, if they use aggregate functions or are dealing with large volumes of data, may also touch tempdb.
This is important to consider when looking at performance. Operations that take place in memory are much faster. As soon as you have to touch spinning disk, things slow down. You also have to consider file placement (is tempdb on the same spinning disk as something else? Are tempdb's data and log files on the same spinning disk as something else?), disk controllers (including iSCSI NICs) and other sources of I/O contention.
As mentioned above, cursors allow you to access data in a result-set on a row-by-row basis.
Here's a design pattern I like to use:
Load a result set into a table-typed variable. Either use a candidate key or a surrogate key (provided by ROW_NUMBER() OVER () ) to loop through the table. With smaller sets, it can be MUCH faster than using a cursor.
For an example using a candidate key from within the resultset, instead of deriving a candidate key from ROW_NUMBER, just use test_data.id to identify a row.
Sorry about the lack of intentation... linkedin strips out leading spaces and tabs.
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'test_data')
DROP TABLE test_data
GO
CREATE TABLE test_data (column_1 nvarchar(255), column_2 nvarchar(255)
GO
INSERT INTO test_data (column_1, column_2)
VALUES
('1', 'one'),
('2', 'two'),
('3', 'three')
('4', 'four')
DECLARE @results TABLE
(
row_id int,
column_1 nvarchar(255),
column_2 nvarchar(255)
)
-- load up @results with only those rows where column_2 starts with 't'
INSERT INTO @results (id, column_1, column_2)
SELECT
ROW_NUMBER() OVER(ORDER BY column_1),
column_1,
column_2
FROM
test_data
WHERE
UPPER(LEFT(column_2, 1)) = 'T'
/* since row_id is a candidate key for @results, use it as a bookmark. */
DECLARE @current_row int
DECLARE @current_column_1 nvarchar(255)
DECLARE @current_column_2 nvarchar(255)
SELECT @current_row = MIN(id) FROM @results
WHILE @current_row IS NOT NULL
BEGIN
SELECT @current_column_1 = column_1, @current_column_2
FROM @results
WHERE id = @current_row
PRINT 'Current Row ID:' + CHAR(9) + CAST(@current_row as varchar)
PRINT 'Current Column_1:' + CHAR(9) + @current_column_1
PRINT 'Current Column_2':' + CHAR(9) + @current_column_2
-- get the next id value and start the loop again.
-- If there are no more rows, @current_row will be NULL,
-- thus exiting the loop
SELECT @current_row = MIN(id)
FROM @results
WHERE id > @current_row
END
How to obfuscate a DLL in .NET?
whatis obfuscate in .NET?? Code access security is alternative of obfuscate.
Obfuscate = it the process of scrambling and encrypting the software so that it CAN NOT be easily reversed engineered. The goal is to stop casual hacking to crack the code.
here is some good links
http://www.csharp411.com/net-obfuscators/
Obfuscate = it the process of scrambling and encrypting the software so that it CAN NOT be easily reversed engineered. The goal is to stop casual hacking to crack the code.
here is some good links
http://www.csharp411.com/net-obfuscators/
Subscribe to:
Posts (Atom)