"--See the space of all database's log file
dbcc sqlperf (logspace)
--back up of simple db
backup log dwd with truncate_only
--reduce size of log file
dbcc shrinkfile (dwd_log,1)"
Search
Wednesday, April 15, 2009
Clear Table ,Stored Procedure,Blank Database
USE
--DB Name
dwd
GO
declare
@procName sysname
declare
someCursor cursor FOR
---- type p mean store prodecure
---- type u Database table
SELECT
name FROM sysobjects WHERE type = 'u' AND objectproperty(id, 'IsMSShipped') = 0
open
someCursor
fetch
next FROM someCursor INTO @procName
while
@@FETCH_STATUS = 0
begin
--type p delete store prodecure from database
--exec('drop proc ' + @procName)
--type u delete table from database
--exec('DROP TABLE ' + @procName)
--type u delete all rows from all table from database (blank db)
--exec('delete from ' + @procName)
--type u for start query identity field number one
exec('dbcc checkident '+'('+ @procName +','+' reseed'+','+'0'+')' )
fetch
next FROM someCursor INTO @procName
end
close
someCursor
deallocate
someCursor
go
--DB Name
dwd
GO
declare
@procName sysname
declare
someCursor cursor FOR
---- type p mean store prodecure
---- type u Database table
SELECT
name FROM sysobjects WHERE type = 'u' AND objectproperty(id, 'IsMSShipped') = 0
open
someCursor
fetch
next FROM someCursor INTO @procName
while
@@FETCH_STATUS = 0
begin
--type p delete store prodecure from database
--exec('drop proc ' + @procName)
--type u delete table from database
--exec('DROP TABLE ' + @procName)
--type u delete all rows from all table from database (blank db)
--exec('delete from ' + @procName)
--type u for start query identity field number one
exec('dbcc checkident '+'('+ @procName +','+' reseed'+','+'0'+')' )
fetch
next FROM someCursor INTO @procName
end
close
someCursor
deallocate
someCursor
go
Tuesday, April 14, 2009
Get Servername dynamatically in Crystal report
private void GetReport(string rptpath)
{
try
{
string dbname = "";
string servername = "";
string UserId = "";
string pwd = "";
servername = ConfigurationManager.AppSettings["ServerName"];
dbname = ConfigurationManager.AppSettings["DatabaseName"];
UserId = ConfigurationManager.AppSettings["UserId"];
pwd = ConfigurationManager.AppSettings["Password"];
crConnectionInfo.ServerName = servername;
crConnectionInfo.DatabaseName = dbname;
crConnectionInfo.UserID = UserId;
crConnectionInfo.Password = pwd;
crReportDocument.Load(Server.MapPath(rptpath));
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables[i];
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
crTable.Location = dbname + ".dbo." + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);
CrystalReportViewer1.ReportSource = crReportDocument;
}
}
catch (Exception ex)
{
throw ex;
}
}
in Web.config we have to write below syntex
{
try
{
string dbname = "";
string servername = "";
string UserId = "";
string pwd = "";
servername = ConfigurationManager.AppSettings["ServerName"];
dbname = ConfigurationManager.AppSettings["DatabaseName"];
UserId = ConfigurationManager.AppSettings["UserId"];
pwd = ConfigurationManager.AppSettings["Password"];
crConnectionInfo.ServerName = servername;
crConnectionInfo.DatabaseName = dbname;
crConnectionInfo.UserID = UserId;
crConnectionInfo.Password = pwd;
crReportDocument.Load(Server.MapPath(rptpath));
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables[i];
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
crTable.Location = dbname + ".dbo." + crTable.Location.Substring(crTable.Location.LastIndexOf(".") + 1);
CrystalReportViewer1.ReportSource = crReportDocument;
}
}
catch (Exception ex)
{
throw ex;
}
}
in Web.config we have to write below syntex
Tuesday, April 7, 2009
Globlization Localization Date
"public DateTime CultureDate(string dat)
{
DateTime condate;
string[] dt = dat.Split('/');
CultureInfo cul = CultureInfo.CurrentCulture;
if (cul.ToString() == 'en-US')
{
return condate = Convert.ToDateTime(dt[1] + '/' + dt[0] + '/' + dt[2]);
}
else if (cul.ToString() == 'en-UK')
{
return condate = Convert.ToDateTime(dt[0] + '/' + dt[1] + '/' + dt[2]);
}
else
{
return condate = Convert.ToDateTime(dt[0] + '/' + dt[1] + '/' + dt[2]);
}
}"
{
DateTime condate;
string[] dt = dat.Split('/');
CultureInfo cul = CultureInfo.CurrentCulture;
if (cul.ToString() == 'en-US')
{
return condate = Convert.ToDateTime(dt[1] + '/' + dt[0] + '/' + dt[2]);
}
else if (cul.ToString() == 'en-UK')
{
return condate = Convert.ToDateTime(dt[0] + '/' + dt[1] + '/' + dt[2]);
}
else
{
return condate = Convert.ToDateTime(dt[0] + '/' + dt[1] + '/' + dt[2]);
}
}"
Thursday, March 19, 2009
Case Statement in Ms-SQL Server
SELECT Partys.PartyId, Partys.PartyName, GRN.ChallanNo, GRNDetail.GrnId, GRNDetail.ChallanQty,
GRNDetail.AcceptQty,
CASE
WHEN challanqty = Acceptqty THEN '55%'
WHEN ((Acceptqty / challanqty) * 100) > 90 THEN '50%'
WHEN ((Acceptqty / challanqty) * 100) > 90 AND ((Acceptqty / challanqty) * 100) < 70 THEN '40%'
WHEN ((Acceptqty / challanqty) * 100) > 70 AND ((Acceptqty / challanqty) * 100) < 50 THEN '25%'
ELSE '0%'
END AS 'Quality',
GRN.PoNo,
Convert(nvarchar,PurchaseOrders.DeliverbyDate,103) as DeliverbyDate,convert(nvarchar,grn.GrnDate,103)AS GrnDate,
Case
when (datediff(day,DeliverbyDate,GrnDate))<= 3 then '45%'
when (datediff(day,DeliverbyDate,GrnDate))> 3 and (datediff(day,DeliverbyDate,GrnDate)) <= 7 then '35%'
when (datediff(day,DeliverbyDate,GrnDate))> 7 and (datediff(day,DeliverbyDate,GrnDate)) <= 10 then '20%'
else
'0%'
end as 'delivery'
FROM GRNDetail
GRNDetail.AcceptQty,
CASE
WHEN challanqty = Acceptqty THEN '55%'
WHEN ((Acceptqty / challanqty) * 100) > 90 THEN '50%'
WHEN ((Acceptqty / challanqty) * 100) > 90 AND ((Acceptqty / challanqty) * 100) < 70 THEN '40%'
WHEN ((Acceptqty / challanqty) * 100) > 70 AND ((Acceptqty / challanqty) * 100) < 50 THEN '25%'
ELSE '0%'
END AS 'Quality',
GRN.PoNo,
Convert(nvarchar,PurchaseOrders.DeliverbyDate,103) as DeliverbyDate,convert(nvarchar,grn.GrnDate,103)AS GrnDate,
Case
when (datediff(day,DeliverbyDate,GrnDate))<= 3 then '45%'
when (datediff(day,DeliverbyDate,GrnDate))> 3 and (datediff(day,DeliverbyDate,GrnDate)) <= 7 then '35%'
when (datediff(day,DeliverbyDate,GrnDate))> 7 and (datediff(day,DeliverbyDate,GrnDate)) <= 10 then '20%'
else
'0%'
end as 'delivery'
FROM GRNDetail
Thursday, March 5, 2009
Monday, March 2, 2009
Print Crystal Report Programatically with Parameter
Print Report On Click Button Or Programatically with Parameter using Below Code
CrystalReportViewer1_Load
{
'Define Report Document
crReportDocument = New ReportDocument()
'Find Current Printer in Local Machine
Dim printDocument As New System.Drawing.Printing.PrintDocument()
crReportDocument.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName
'find path of report
Path = Application.StartupPath
Path = Mid(Path, 1, Len(Path) - 9)
'load printer
crReportDocument.Load(Path & "\test2.rpt")
'pass Peramter
crReportDocument.SetParameterValue("@invoiceid", invoiceno)
CrystalReportViewer1.ReportSource = crReportDocument
'Assign User name and database name for avoid error Answer
'Incorrect Log on Parameters
crReportDocument.SetDatabaseLogon("sa", "pass#word1", ".\sqlexpress","TATA")
'Print report using Printer
crReportDocument.PrintToPrinter(1, True, 1, 1)
}
End Sub
Subscribe to:
Posts (Atom)