Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Thursday, March 22, 2012

Error: 26 - Error Locating Server/Instance Specified - (My hosting company says it's in my conn

Hi All...

I am trying to move my site (incomplete) for testing and I am finding that the Db connection process to be

the most difficult, well back to my problem. I can't seem to get past this error and am frustrated with overall

connectivity problems. Please help!!!

===================================================================================

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

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: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[SqlException (0x80131904): An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735123 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +820 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +130 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105 System.Data.SqlClient.SqlConnection.Open() +111 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +84 System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +197 System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +1121 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42 System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +83 System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +160 System.Web.UI.WebControls.Login.AttemptLogin() +105 System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +99 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210

Now you all must admit that, if your somewhat new to this databasing, It's a ***.

The source for my application is Visual Web Designer 2005 Express

It is an ASP.Net driven site with membership roles and all the good stuff.

the latest theory is that I need to change the provider config in the web.config file from AspNetSqlProvider

to something else. Most of my complications and frustrations come from GoDaddy and no access to the

shared server (understandibly).

I hope I gave enough info for help and not too much.. Smile

Dave

Please check this blog for solutions:

http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx

sql

Friday, February 24, 2012

Error while using OUTPUT clause - The multi-part identifier could not be bound

I was trying to copy child records of one parent record into another, and wanted to report back new child record id and corresponding child record id that was used to create it. I ran into run-time error with OUTPUT clause. Following is a script that will duplicate the situation I ran into:

CREATE TABLE Parent(

ParentID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,

ParentName VARCHAR(50) NOT NULL)

GO

CREATE TABLE Child(

ChildID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,

ParentID INT NOT NULL REFERENCES Parent(ParentID),

ChildName VARCHAR(50) NOT NULL)

GO

INSERT INTO Parent(ParentName) VALUES('Parent 1')

INSERT INTO Parent(ParentName) VALUES('Parent 2')

GO

INSERT INTO Child(ParentID, ChildName) VALUES(1, 'Child 1')

INSERT INTO Child(ParentID, ChildName) VALUES(1, 'Child 2')

GO

At this stage, there Child table looks like:

ChildID

ParentID

ChildName

1

1

Child 1

2

1

Child 2

What I want to do is copy Parent 1’s children to Parent 2, and report back which source ChildID that was used to create the new child records. So I wrote the query:

DECLARE @.LinkTable TABLE (FromChildID INT, ToChildID INT)

INSERT INTO Child(ParentID, ChildName)

OUTPUT c.ChildID, inserted.ChildID INTO @.LinkTable

SELECT 2, c.ChildName

FROM Child c

WHERE c.ParentID = 1

SELECT * FROM @.LinkTable

In the end I was expecting Child table to look like:

ChildID

ParentID

ChildName

1

1

Child 1

2

1

Child 2

3

2

Child 1

4

2

Child 2

and OUTPUT clause to return me:

FromChildID

ToChildID

1

3

Child record with ID 3 was created using ID of 1.

2

4

Child record with ID 4 was created using ID of 2.

But infact I’m getting following error:

Msg 4104, Level 16, State 1, Line 9

The multi-part identifier "c.ChildID" could not be bound.

Any ideas on how to fix the OUTPUT clause in the query to return me the expected output?

Thanks

Yogesh

This is not possible because the INSERT statement doesn’t have a FROM clause. The UPDATE and DELETE however has the non-standard TSQL specific FROM clause as part of the DML statement itself so you can reference those tables in the OUTPUT clause. You can only do INSERT….VALUES or INSERT..SELECT or INSERT…EXECUTE. So you can only reference the inserted table. And the INSERT DML itself cannot reference other tables (except you can now use CTE in SQL Server 2005 and reference it as target table of insert which is non-standard also).

See the link below for the OUTPUT clause usage (also documents where you can use from_table_name in the OUTPUT clause column list):

http://msdn2.microsoft.com/en-us/ms177564(SQL.90).aspx

In your example, you need to reference the inserted table columns:

INSERT INTO Child(ParentID, ChildName)

OUTPUT inserted.ParentID, inserted.ChildID INTO @.LinkTable

SELECT 2, c.ChildName

FROM Child c

WHERE c.ParentID = 1

|||

Thanks a bunch Umachandar for your prompt reply. I really need the output as I explained earlier. I played with CTE as per your suggestion for a while but I could not get records inserted into my @.LinkTable table variable as I wanted. Finally as a last option I tried with cursors, and got the source and target child id output.

I’m not terribly worried about poor performance of cursor because this stored procedure will be called only once in 6 months when no one else but admin of my application is logged in. What are your thoughts on using this in production app given these circumstances?

DECLARE

@.ChildID int,

@.ChildName varchar(50)

DECLARE child_cur CURSOR FORWARD_ONLY READ_ONLY FOR

SELECT ChildID, ChildName

FROM Child

WHERE ParentID = 1

DECLARE @.LinkTable TABLE (FromChildID INT, ToChildID INT)

OPEN child_cur

FETCH child_cur INTO @.ChildID, @.ChildName

WHILE @.@.fetch_status = 0

BEGIN

INSERT INTO Child(ParentID, ChildName)

OUTPUT @.ChildID, inserted.ChildID INTO @.LinkTable

VALUES (2, @.ChildName)

FETCH child_cur INTO @.ChildID, @.ChildName

END

CLOSE child_cur

DEALLOCATE child_cur

SELECT * FROM @.LinkTable

This code gave my expected output:

FromChildID

ToChildID

1

3

2

4

|||

I didn't mean to imply that using a CTE as target for the insert statement will work. It is just not possible to reference other tables in the OUTPUT clause of INSERT DML. Your code looks fine except that I don't see the need for OUTPUT clause at all. You can just do below:

DECLARE

@.ChildID int,

@.ChildName varchar(50)

DECLARE child_cur CURSOR FORWARD_ONLY READ_ONLY FOR

SELECT ChildID, ChildName

FROM Child

WHERE ParentID = 1

DECLARE @.LinkTable TABLE (FromChildID INT, ToChildID INT)

OPEN child_cur

WHILE (1=1)

BEGIN

FETCH child_cur INTO @.ChildID, @.ChildName

IF @.@.FETCH_STATUS < 0 BREAK

INSERT INTO Child(ParentID, ChildName) VALUES (2, @.ChildName)

INSERT INTO @.LinkTable VALUES (@.ChildID, SCOPE_IDENTITY())

END

CLOSE child_cur

DEALLOCATE child_cur

SELECT * FROM @.LinkTable

Alternatively, if the ChildName is unique per parent (your schema doesn't seem to imply if this is the case) then you can simply get the link table values by doing following query:

SELECT c1.ChildID AS FromChildID, c2.ChildID AS ToChildID

FROM Child as c1

JOIN Child as c2

ON c2.ChildName = c1.ChildName

WHERE c2.ParentID = 2

AND c1.ParentID = 1

So by putting the necessary constraints on your data model you can answer most questions efficiently.

|||

I have similer problem, I need to return with OUTPUT clause field from the SELECT clause in insert statement.
If I'll do it as suggested using CURSOR, it going to take a lot of time.

CREATE TABLE [dbo].[ProductsMapping](

[OldProductID] [int] NOT NULL,

[NewProductID] [int] NOT NULL,

[ProductName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[IsNEQ] [bit] NOT NULL,

[IsNew] [bit] NOT NULL,

CONSTRAINT [PK_ProductsMapping] PRIMARY KEY NONCLUSTERED

(

[OldProductID] ASC

,[NewProductID] ASC

)WITH FILLFACTOR = 90 ON [PRIMARY]

) ON [PRIMARY]

CREATE TABLE [dbo].[Products](

[ProductID] [int] IDENTITY(1,1) NOT NULL,

[ProductName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

CONSTRAINT [PK_Products] PRIMARY KEY NONCLUSTERED

(

[ProductID] ASC

)WITH FILLFACTOR = 90 ON [PRIMARY]

) ON [PRIMARY]

INSERT INTO ProductsMapping

(OldProductID

,NewProductID

,ProductName

,IsNEQ

,IsNew)

SELECT o.ProductID OldProductID

,isnull(n.ProductID,o.ProductID) NewProductID

,o.ProductName

,(isnull(n.ProductID,0)-o.ProductID) IsNEQ

,isnull(n.ProductID,0) IsNew

FROM LINKEDSRV.DB.dbo.Products o

LEFT OUTER JOIN Products n ON n.ProductName = o.ProductName

DECLARE @.NewProducts TABLE (

[OldProductID] [int] NOT NULL,

[NewProductID] [int] NOT NULL,

[ProductName] [varchar](50))

DECLARE @.OldProductID int

DECLARE @.ProductName varchar(50)

DECLARE NewProduct_cur CURSOR FORWARD_ONLY READ_ONLY FOR

SELECT w.ProductName

,w.OldProductID

FROM ProductsMapping w

WHERE w.IsNew=1

OPEN NewProduct_cur

FETCH NewProduct_cur INTO @.ProductName, @.OldProductID

WHILE @.@.fetch_status = 0

BEGIN

INSERT INTO Products(ProductName)

OUTPUT INSERTED.ProductID AS NewProductID

,INSERTED.ProductName AS ProductName

,@.OldProductID AS OldProductID

INTO @.NewProducts

VALUES (@.ProductName)

END

CLOSE NewProduct_cur

DEALLOCATE NewProduct_cur

UPDATE ProductsMapping

SET NewProductID=t.NewProductID

FROM ProductsMapping w

INNER JOIN @.NewProducts t ON t.OldProductID=w.OldProductID

AND IsNew=1

I also tried CTE and it doesn't work.

Do you have any suggestion how to do it with out cursor?

THNX

Jermy

Error while using OUTPUT clause - The multi-part identifier could not be bound

I was trying to copy child records of one parent record into another, and wanted to report back new child record id and corresponding child record id that was used to create it. I ran into run-time error with OUTPUT clause. Following is a script that will duplicate the situation I ran into:

CREATE TABLE Parent(

ParentID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,

ParentName VARCHAR(50) NOT NULL)

GO

CREATE TABLE Child(

ChildID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,

ParentID INT NOT NULL REFERENCES Parent(ParentID),

ChildName VARCHAR(50) NOT NULL)

GO

INSERT INTO Parent(ParentName) VALUES('Parent 1')

INSERT INTO Parent(ParentName) VALUES('Parent 2')

GO

INSERT INTO Child(ParentID, ChildName) VALUES(1, 'Child 1')

INSERT INTO Child(ParentID, ChildName) VALUES(1, 'Child 2')

GO

At this stage, there Child table looks like:

ChildID

ParentID

ChildName

1

1

Child 1

2

1

Child 2

What I want to do is copy Parent 1’s children to Parent 2, and report back which source ChildID that was used to create the new child records. So I wrote the query:

DECLARE @.LinkTable TABLE (FromChildID INT, ToChildID INT)

INSERT INTO Child(ParentID, ChildName)

OUTPUT c.ChildID, inserted.ChildID INTO @.LinkTable

SELECT 2, c.ChildName

FROM Child c

WHERE c.ParentID = 1

SELECT * FROM @.LinkTable

In the end I was expecting Child table to look like:

ChildID

ParentID

ChildName

1

1

Child 1

2

1

Child 2

3

2

Child 1

4

2

Child 2

and OUTPUT clause to return me:

FromChildID

ToChildID

1

3

Child record with ID 3 was created using ID of 1.

2

4

Child record with ID 4 was created using ID of 2.

But infact I’m getting following error:

Msg 4104, Level 16, State 1, Line 9

The multi-part identifier "c.ChildID" could not be bound.

Any ideas on how to fix the OUTPUT clause in the query to return me the expected output?

Thanks

Yogesh

This is not possible because the INSERT statement doesn’t have a FROM clause. The UPDATE and DELETE however has the non-standard TSQL specific FROM clause as part of the DML statement itself so you can reference those tables in the OUTPUT clause. You can only do INSERT….VALUES or INSERT..SELECT or INSERT…EXECUTE. So you can only reference the inserted table. And the INSERT DML itself cannot reference other tables (except you can now use CTE in SQL Server 2005 and reference it as target table of insert which is non-standard also).

See the link below for the OUTPUT clause usage (also documents where you can use from_table_name in the OUTPUT clause column list):

http://msdn2.microsoft.com/en-us/ms177564(SQL.90).aspx

In your example, you need to reference the inserted table columns:

INSERT INTO Child(ParentID, ChildName)

OUTPUT inserted.ParentID, inserted.ChildID INTO @.LinkTable

SELECT 2, c.ChildName

FROM Child c

WHERE c.ParentID = 1

|||

Thanks a bunch Umachandar for your prompt reply. I really need the output as I explained earlier. I played with CTE as per your suggestion for a while but I could not get records inserted into my @.LinkTable table variable as I wanted. Finally as a last option I tried with cursors, and got the source and target child id output.

I’m not terribly worried about poor performance of cursor because this stored procedure will be called only once in 6 months when no one else but admin of my application is logged in. What are your thoughts on using this in production app given these circumstances?

DECLARE

@.ChildID int,

@.ChildName varchar(50)

DECLARE child_cur CURSOR FORWARD_ONLY READ_ONLY FOR

SELECT ChildID, ChildName

FROM Child

WHERE ParentID = 1

DECLARE @.LinkTable TABLE (FromChildID INT, ToChildID INT)

OPEN child_cur

FETCH child_cur INTO @.ChildID, @.ChildName

WHILE @.@.fetch_status = 0

BEGIN

INSERT INTO Child(ParentID, ChildName)

OUTPUT @.ChildID, inserted.ChildID INTO @.LinkTable

VALUES (2, @.ChildName)

FETCH child_cur INTO @.ChildID, @.ChildName

END

CLOSE child_cur

DEALLOCATE child_cur

SELECT * FROM @.LinkTable

This code gave my expected output:

FromChildID

ToChildID

1

3

2

4

|||

I didn't mean to imply that using a CTE as target for the insert statement will work. It is just not possible to reference other tables in the OUTPUT clause of INSERT DML. Your code looks fine except that I don't see the need for OUTPUT clause at all. You can just do below:

DECLARE

@.ChildID int,

@.ChildName varchar(50)

DECLARE child_cur CURSOR FORWARD_ONLY READ_ONLY FOR

SELECT ChildID, ChildName

FROM Child

WHERE ParentID = 1

DECLARE @.LinkTable TABLE (FromChildID INT, ToChildID INT)

OPEN child_cur

WHILE (1=1)

BEGIN

FETCH child_cur INTO @.ChildID, @.ChildName

IF @.@.FETCH_STATUS < 0 BREAK

INSERT INTO Child(ParentID, ChildName) VALUES (2, @.ChildName)

INSERT INTO @.LinkTable VALUES (@.ChildID, SCOPE_IDENTITY())

END

CLOSE child_cur

DEALLOCATE child_cur

SELECT * FROM @.LinkTable

Alternatively, if the ChildName is unique per parent (your schema doesn't seem to imply if this is the case) then you can simply get the link table values by doing following query:

SELECT c1.ChildID AS FromChildID, c2.ChildID AS ToChildID

FROM Child as c1

JOIN Child as c2

ON c2.ChildName = c1.ChildName

WHERE c2.ParentID = 2

AND c1.ParentID = 1

So by putting the necessary constraints on your data model you can answer most questions efficiently.

|||

I have similer problem, I need to return with OUTPUT clause field from the SELECT clause in insert statement.
If I'll do it as suggested using CURSOR, it going to take a lot of time.

CREATE TABLE [dbo].[ProductsMapping](

[OldProductID] [int] NOT NULL,

[NewProductID] [int] NOT NULL,

[ProductName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

[IsNEQ] [bit] NOT NULL,

[IsNew] [bit] NOT NULL,

CONSTRAINT [PK_ProductsMapping] PRIMARY KEY NONCLUSTERED

(

[OldProductID] ASC

,[NewProductID] ASC

)WITH FILLFACTOR = 90 ON [PRIMARY]

) ON [PRIMARY]

CREATE TABLE [dbo].[Products](

[ProductID] [int] IDENTITY(1,1) NOT NULL,

[ProductName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,

CONSTRAINT [PK_Products] PRIMARY KEY NONCLUSTERED

(

[ProductID] ASC

)WITH FILLFACTOR = 90 ON [PRIMARY]

) ON [PRIMARY]

INSERT INTO ProductsMapping

(OldProductID

,NewProductID

,ProductName

,IsNEQ

,IsNew)

SELECT o.ProductID OldProductID

,isnull(n.ProductID,o.ProductID) NewProductID

,o.ProductName

,(isnull(n.ProductID,0)-o.ProductID) IsNEQ

,isnull(n.ProductID,0) IsNew

FROM LINKEDSRV.DB.dbo.Products o

LEFT OUTER JOIN Products n ON n.ProductName = o.ProductName

DECLARE @.NewProducts TABLE (

[OldProductID] [int] NOT NULL,

[NewProductID] [int] NOT NULL,

[ProductName] [varchar](50))

DECLARE @.OldProductID int

DECLARE @.ProductName varchar(50)

DECLARE NewProduct_cur CURSOR FORWARD_ONLY READ_ONLY FOR

SELECT w.ProductName

,w.OldProductID

FROM ProductsMapping w

WHERE w.IsNew=1

OPEN NewProduct_cur

FETCH NewProduct_cur INTO @.ProductName, @.OldProductID

WHILE @.@.fetch_status = 0

BEGIN

INSERT INTO Products(ProductName)

OUTPUT INSERTED.ProductID AS NewProductID

,INSERTED.ProductName AS ProductName

,@.OldProductID AS OldProductID

INTO @.NewProducts

VALUES (@.ProductName)

END

CLOSE NewProduct_cur

DEALLOCATE NewProduct_cur

UPDATE ProductsMapping

SET NewProductID=t.NewProductID

FROM ProductsMapping w

INNER JOIN @.NewProducts t ON t.OldProductID=w.OldProductID

AND IsNew=1

I also tried CTE and it doesn't work.

Do you have any suggestion how to do it with out cursor?

THNX

Jermy