Showing posts with label SQL Server 2008. Show all posts
Showing posts with label SQL Server 2008. Show all posts

Saturday

Could not open a connection to SQL Server

Introduction

One day, I was attempting to connect with MS SQL Server but it didn't succeeded not even after making attempt once more and once more. I ran into error provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server on server. I'm providing you all necessary steps to resolve issue error: 40 - Could not open a connection to SQL Server. To succeed this issue, I would recommend to experience gave all strides one by one until your issue get resolve. This error comes out in many ways so that you need to check out all steps provided in this article until you succeed your issue.  

Detail Error Description:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1016


Sunday

How to Design Entity Relationship Diagram

Entity Relation Diagram (ER-Diagram) is very important aspect of database designing, with the help of ER Diagram we can define Primary Keys, Foreign Keys, Unique Keys so entire relations in our schema. I have suggested key steps to design fantastic ER-Diagram.

How to Schedule Backup in SQL Server ?

Introduction

I am writing about very important part of our development How to schedule backup in SQL Server. We work sometimes offline (at our local machine) or online server, our day-to-day database development backup versions are very important in our SDLC. If we are working & omitting important information from back end MS SQL Server, It pulls back us, we need put extra efforts to recover the lost time of development.  I have provided below steps how to schedule backup in SQL server?

Step 1: Open Microsoft SQL Server Management Studio to schedule a backup plan in SQL Server.
Step 2: Then expand Management > folder

Management

Step 3: Open Management > Maintenance Plans folder.

Management Plans
Step 4: Right Click on “Maintenance Plans” & context Menu contains “New Maintenance Plans…

New Maintenance Plan

Step 5: A popup window will open to write your Maintenance Plan name.

New Maintenance Plan








Step 6: Left side a toolbox window will open where you can drag & drop “Backup Database Task” option.

Maintenance Plans Task

Step 7: Now two part of window will be shown upper part have Plan Name, Schedule, and Plan Description and lower part contain “Backup Database Task Plan”.


Step 8:  Once drag & drop "Back Up Database Task", now on lower part you can see Back up database task window

Back up Database Task



Step 9: Right click on “Backup Database Task Plan” contains on lower part of window and click on “Edit” option.

Backup Database Task

Step 10: Now a new window will pop up where have different options to schedule your back up plan i.e. Connection, Backup Type, Database (Select databases as per requirements) etc.

Backup Database Task

Step 11: Now at the bottom of “Backup Database Task Plan” there is an option to check option “Create a sub-directory of each database” and we can set back plan “Folder” path.

Backup Database Task

Step 12: Upper part of Window there is a button to schedule maintenance day and time.

Maintenance Plan Task

Step 13. A new window will open with name “Job Schedule Properties”, sub plan name, Schedule Name, “Frequency” have Occurs, Recurs every, Daily frequency, Duration, Summary.

Job Schedule Properties

Step 14. You have done all steps now click on “OK” button.

Your Management studio is not showing all list of configuring option, I have given below stored procedure run in your query analyzer & will up show advanced configuration options.

sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Agent XPs', 1;
GO
RECONFIGURE
GO

Summary

If you have done carefully all above 14 steps, It will help you schedule your backup maintenance plan moreover I have provided snapshots of each item so you can understand well when you are going to implement on to your machine.

Video: How to Schedule Backup in SQL Server

Suggested Reading

Friday

How to write in Text file on desktop in vb.net

Introduction

Here, in this article showing how to write in Text file on desktop in vb.net. We can use namespace System.Environment.GetFolderPath to get the desktop folder. If particular folder is not created on windows desktop then this code will fully capable to create folder on desktop. if the write to text file already exists then it will delete existed file and then again create a new file and write this text file. Already explained in my previous article Create Folder on Desktop in ASP.NET.

Public Function WriteToText(ByVal obj As String, ByVal FileName As String) As Boolean
Dim FilePath As String

FilePath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
FilePath &= "\Sample\Test\"

Try
    If Not System.IO.Directory.Exists(FilePath) Then
        Dim di As DirectoryInfo = System.IO.Directory.CreateDirectory(FilePath)
    End If

    FilePath &= FileName
    If System.IO.File.Exists(FilePath) = True Then
        System.IO.File.Delete(FilePath)
    End If

    Dim fi As FileInfo = New FileInfo(FilePath)
    Dim sw As StreamWriter
    If Not fi.Exists Then
        sw = fi.CreateText()
        sw.Write(obj)
        sw.Flush()
        sw.Close()
    End If
Catch ex As Exception
    MessageBox.Show("Writting to test folder error occurred!" + ex.Message.ToString)
    Return False
End Try
Return True
End Function

C# Code Snippet

public bool WriteToText(string obj, string FileName)
{
 string FilePath = null;

 FilePath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
 FilePath += "\\Sample\\Test\\";

 try {
  if (!System.IO.Directory.Exists(FilePath)) {
   DirectoryInfo di = System.IO.Directory.CreateDirectory(FilePath);
  }

  FilePath += FileName;
  if (System.IO.File.Exists(FilePath) == true) {
   System.IO.File.Delete(FilePath);
  }

  FileInfo fi = new FileInfo(FilePath);
  StreamWriter sw = default(StreamWriter);
  if (!fi.Exists) {
   sw = fi.CreateText();
   sw.Write(obj);
   sw.Flush();
   sw.Close();
  }
 } catch (Exception ex) {
  MessageBox.Show("Writting to test folder error occurred!" + ex.Message.ToString);
  return false;
 }
 return true;
}

Conclusion

In this article, I have explained this article with code snippet on How to write in Text file on desktop in vb.net. Hope it will help to everyone to write in text file on desktop.

Summary