Friday, November 16, 2012
select column in PDF, Vertical test select in pdf
hold Alt key and then select PDF column it will select vertical.
Friday, November 9, 2012
Cannot add an entity with a key that is already in use, LINQ
-- When you get above error there are two possibility
1) you are trying to insert duplicate primary key.
2) when you have SQL column with data type = "Uniqueidentifier" and default set to 'NewID()'
that means its auto-generated field.
Make sure in you DBML file that tale > field > properties > "Auto Generated Value" is set to true
default is fault
Monday, October 15, 2012
Operand type clash: int is incompatible with uniqueidentifier
When you get above error please double check following
- you are inserting into table from view
- table has column with data type - uniqueidentifier with allow null
- view is returning null for uniqueidentifier field
- you have to convert null to uniqueidentifier field in view
for example ,convert(uniqueidentifier,null) as MyUniqueIdentifierField
Tuesday, October 2, 2012
Autogenerate get and set class properties
1) use notepad ++ to generate class private properties
2)
You can right-click on the field and go to Refactor > Encapsulate Field. That will generate a public Property. You still have to do each one at a time but it's a lot faster than the typing!
Thursday, September 27, 2012
sqlbulkcopy with transaction
string connstring = _hsconnstring.Substring(1, (_myconnstring.Length - 1));
using (SqlConnection destinationConnection = new SqlConnection((connstring)))
{
destinationConnection.Open();
using (SqlTransaction transaction = destinationConnection.BeginTransaction())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection,SqlBulkCopyOptions.Default,transaction))
{
try
{
bulkCopy.DestinationTableName = "myfirsttable";
bulkCopy.WriteToServer(outTable1);
bulkCopy.DestinationTableName = "mysecondtable";
bulkCopy.WriteToServer(outTable2);
bulkCopy.DestinationTableName = "mythirdtable";
bulkCopy.WriteToServer(outTable3);
bulkCopy.DestinationTableName = "myfouthtable";
bulkCopy.WriteToServer(outTable4);
bulkCopy.DestinationTableName = "myfifthtable";
bulkCopy.WriteToServer(outTable5);
bulkCopy.Close();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
Utilities.HandleError("Error at data bulk insert: ", ex);
throw ex;
}
}
}
}
number of current open sql session using query
--SP
exec sp_who
--QUERY
SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NumberOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
order by DB_NAME(dbid)
Monday, September 24, 2012
SQL create split function and how to use function in sql
ALTER FUNCTION [dbo].[Split](@String varchar(8000), @Delimiter char(1))
returns @temptable TABLE (items varchar(8000))
as
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 br="br" is="is" nbsp="nbsp" null="null" or="or" return="return" tring="tring">
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end
GO1>
--- How to call the function
select * from [dbm].[Split] ('L196,L201,L197',',')
Subscribe to:
Posts (Atom)