Thursday, September 10, 2009

SQL Server 2005 Linked Server using TSQL

Use the below to commands to add a server as linked server:

To Add the Server:
sp_addlinkedserver 'Alias Name', '', 'SQLNCLI', NULL, NULL, 'SERVER=IP', NULL

To Add the security:
sp_addlinkedsrvlogin 'Alias Name', 'false', NULL, 'User Name', 'Password'

NOTE: When you are trying to connect SQL Server 2000 to SQL Server 2005 as Linked server you may get the following error:

OLE DB provider "SQLNCLI" for linked server "serv01" returned message "Unspecified error".

OLE DB provider "SQLNCLI" for linked server "serv01" returned message "The stored procedure required to complete this operation could not be found on the server. Please contact your system administrator.".

Msg 7311, Level 16, State 2, Line 1

Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI" for linked server "serv01". The provider supports the interface, but returns a failure code when it is used.


Solution is specified in this link.

What worked for me is this

SELECT * FROM OPENQUERY(LinkedServerAlias,'SELECT * FROM [Fully Qualified Name')

Sunday, June 21, 2009

CRM 4.0 Calling Web Service

public static CrmService GetCrmService(string orgName, string server)
{

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = orgName;

CrmService service = new CrmService();

service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.CrmAuthenticationTokenValue = token;
service.Url = string.Format("http://{0}/mscrmservices/2007/crmservice.asmx", server);
return service;

}

Friday, April 24, 2009

How to ouput the results to File (SQL Server)

Either do Control + shift + F
or
Go to Query -> Result To -> Select "Output to file"
Now when you will run the query, system will ask for the file to save the results.

Friday, April 17, 2009

difference between the console.read and console.readlline

Console.Readline reads the entire line of data.
Console.Read reads only one character at a time.
Console.Write will writes to the screen and leaves the cursor until the user hits enter.
Console.WriteLine writes to the screen and will perform a carriage return and line-feed.

Wednesday, April 15, 2009

How to create the proxy class from WSDL

Open Start-> visual Studio 2008 -> Tools -> Command prompt

browse to the desired directory

and type

wsdl www.wsdlurl.com/wsdl

and a file will be created

Tuesday, April 14, 2009

How to use Foreach in c# Arrays

string[] WeeKdays = new string[7];

WeeKdays[0] = Sunday";
WeeKdays[1] = "Monday";
WeeKdays[2] = "Tuesday";
WeeKdays[3] = "Wednesday";
WeeKdays[4] = "Thursday";
WeeKdays[5] = "Friday";
WeeKdays[6] = "Saturday";

foreach (object row in Weekdays)
{
Response.Write(row + " , ");
}

Thursday, April 9, 2009

Loop through each row in dataset

foreach (DataRow row in dsDataset.Tables[0].Rows)
{
Console.writeline(row["ColmnName1"].tostring();
Console.writeline(row["ColmnName2"].tostring();
.
.
.
}