Skip to main content

Posts

Showing posts from 2015
How to get database list using sql command> Below link more helpfull for get database list. https://www.simple-talk.com/sql/database-administration/exploring-your-sql-server-databases-with-t-sql/ 1. Basic Server Information -- Server and instance name Select   @@SERVERNAME   as   [Server\Instance] ; -- SQL Server Version Select   @@VERSION   as   SQLServerVersion ; -- SQL Server Instance Select   @@ServiceName   AS   ServiceInstance ; -- Current Database Select   DB_NAME ()   AS   CurrentDB_Name ; -- Note the tempdb system database is recreated every time the server restarts -- Thus this is one method to tell when the database server was last restarted SELECT    @@Servername   AS   ServerName   ,          create_date   AS   ServerStarted   ,          DATEDIFF ( s , ...
How to restore database using sql command? RESTORE DATABASE Test1 FROM  DISK = N'C:\inetpub\PoologicDatabaseBakFile\PoologicDataBase.bak'   WITH REPLACE,   MOVE 'PoologicsBakFile' TO 'C:\inetpub\PoologicDatabaseBakFile\Test1.mdf',   MOVE 'PoologicsBakFile_log' TO 'C:\inetpub\PoologicDatabaseBakFile\Test1.ldf';
How to download partial view content using c#? private static string CallApplicationControllerForSnapshotHtml(Guid subscriberId, int duration, long? subscriberUserId, string conString)         {             string myUrl = string.Format(ServiceConfigurationHelper.GetAppSettingValue("GetHtmlContentUrl") + "?subscriberId={0}&duration={1}&SubscriberUserId={2}&conString={3}", subscriberId, duration, subscriberUserId, conString);             WebClient wc = new WebClient();             string requestResult = wc.DownloadString(myUrl);             return requestResult;         }
How to make time format in AM PM in c#? Add below code in function.  static DateTimeFormatInfo timeFormat = new DateTimeFormatInfo();  timeFormat.ShortTimePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;  timeFormat.AMDesignator = "AM";  timeFormat.PMDesignator = "PM";         public static string GetCurrentTime         {             get             {                 return String.Format(timeFormat, "{0:t}", DateTime.UtcNow).Replace(" ", "");             }         }
How to create window service using timer?  Timer timerDailyReport = new Timer();  protected override void OnStart(string[] args)         {             try             {                               StartTimer(timerDailyReport, 60000, timerDailyReport_Elapsed);                           }             catch (Exception ex)             {                 ErrorLog.WriteonError("OnStart " + ex.Message.ToString());             }         } private void StartTimer(Timer timer, long interval, ElapsedEventHandler events)         {             timer.Int...
How to write txt file using c# code.  public class ErrorLog     {         public static void WriteonError(string exception)         {             string filepath = AppDomain.CurrentDomain.BaseDirectory + "/ErrorLog.txt";             if (File.Exists(filepath))             {                 using (StreamWriter writer = new StreamWriter(filepath, true))                 {                     writer.Write("" + DateTime.Now.ToString() + " : " + exception);                     writer.Write(Environment.NewLine);                     writer.Write(Environment.NewLine);             ...
How to install window service using command prompt. c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe "your service path" If you want uninstall window service then use below code: c:\windows\microsoft.net\framework\v4.0.30319\installutil.exe /u "your service path"
How to read multi-pal result set from entity framework. Model objModel = new Model();   using (var context = new DBContext())             {                 try                 {                     context.Database.Initialize(force: false);                     // Create a SQL command to execute the sproc                     var cmd = context.Database.Connection.CreateCommand();                     cmd.CommandText = "EXEC [sp_Name] @SubscriberId,@Duration,@SubscriberUserId";                     cmd.Parameters.Add(new SqlParameter("SubscriberId", SubscriberId));               ...
How to convert string time to 24 Hours format in SQL. Declare @Test datetime Select  @Test=CONVERT(datetime, '06:59PM' , 120) Select Cast(@Test as time(0))