I have a stored procedure that creates a new linked server.
The problem is that my InstanceName is "my-pc" (contains "-"), and therefore the LinkedServer is not generated correctly. My guess is that there is a problem in the way I pass the parameter from my c# code, but I couldn't find a solution for that.
My procedure is:
CREATE PROCEDURE
[test].[createlinkedserver]
(
@InstanceName AS SYSNAME
)
AS
BEGIN
EXECUTE sys.sp_addlinkedserver
@server = N'Server' ,
@srvproduct = N'' ,
@provider = N'SQLNCLI' ,
@datasrc = [@InstanceName] ,
@location = NULL ,
@provstr = NULL ,
@catalog = NULL
EXECUTE master.dbo.sp_serveroption
@server = N'Server' ,
@optname = N'rpc out' ,
@optvalue = N'true'
EXECUTE master.dbo.sp_serveroption
@server = N'Server' ,
@optname = N'remote proc transaction promotion' ,
@optvalue = N'true'
END
and I call the stored procedure from c#:
DbCommand Command = CovertixDB.Database.GetStoredProcCommand("test.createlinkedserver");
CovertixDB.Database.AddInParameter(Command, "InstanceName", DbType.String, instanceName);
CovertixDB.Database.ExecuteNonQuery(Command);