Sunday, January 30, 2011

Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server.

Error: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

If you encounter above error, while running your VS.Net, than first thing you should do is to check your web.config file to make sure that connection string is correct.

This problem might occur if you have recently

  • Change your PC Name
  • Installed new sql server instance but have not updated your web.config file with correct instance name.


Example:
Earlier you were using instance name "YourPCName\SQLExpress" but due to new sql server instance installation your instance name changed to "YourPCName\CustomInstanceName".

Below is sample connection string, where text in red is cause of problem.
Data Source=MyPCName\MySQLInstance;Initial Catalog=MyDBName;Integrated Security=True


Solution
Check Connection string in your vs.net solutions, web.config file and correct with new sql server instance name.

Tuesday, January 25, 2011

Related Links - FullText Search Query Example

In any application generating related links is little challenging and it is very hard to get accurate result.  I have try to create example of related link query which will fetch close result of what you are looking for.

Consider an example of any website with article section and if you are trying to give related links using fulltext search query of sql server, than following query would be helpful.

If you are new to fulltext search and would like to understand more on how fulltext search works in sql server

Step 1: Check whether fulltext search is installed
Select SERVERPROPERTY('IsFullTextInstalled')
If this query returns a value of '1' then the component is installed.



Step 2: Create FullText Catalog
Create FullText Catalog MyDBNameCatalog

Step 3: Create FullText Index on Table
Create FullText Index on ArticlesTable
(ArticleTitle)
Key Index PK_ArticleTable_ArticleID on MyDBNameCatalog
with Change_Tracking Auto


Step 4: Creating Query - Example Query Related Links for Article in SQL Server
Select ftt.Rank, *
from ArticleTable
Inner Join FreeTextTable(ArticleTable, ArticleTitle, 'ISABOUT("My Search Text")') as ftt
on ftt.[Key] = ArticleTable.ArticleId
Order by ftt.Rank desc


Step 5: Now you are ready to create stored procedure which can return related links

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[ArticleTable_ReleatedLinks_FullTextSearch]
@ArticleId bigint,
@ArticleTitle varchar(500),
@iErrorCode int OUTPUT
AS
SET NOCOUNT ON

set  @ArticleTitle = 'ISABOUT(' +  @ArticleTitle + ')'

SELECT Top 20
ArticleTable.[ArticleId],
ArticleTable.[ArticleTitle]
FROM ArticleTable
Inner Join FreeTextTable(ArticleTable, ArticleTitle, @ArticleTitle) as ftt
on ftt.[Key] = ArticleTable.ArticleId
Where
ArticleTable.ArticleId != @ArticleId
ArticleTable.IsDeleted = 0
Order by ftt.Rank desc
-- Get the Error Code for the statement just executed.
SELECT @iErrorCode=@@ERROR

To understand about how FreeTextTable query works and for more examples and syntax

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape