Thursday, December 7, 2017

Power Shell: Remove feature from SharePoint content database

Leave a Comment
During migration from Project server 2010 to Project server 2016, I faced missing feature error with Test-SPContentDatabase, so following script did the trick:

Remove-SPFeatureFromContentDB -ContentDB "ContentDBName" -FeatureId "FeatureID_GUID"
Read More

How to download deployed WSP from SharePoint central admin through PowerShell

Leave a Comment
This blog post is related to normal queries of SharePoint guys when they need to get deployed WSPs from SharePoint. I involved in migration of Project Server 2010 to Project Server 2016 so I need deployed WSP while testing mount database.

Following is simple script for downloading WSP through Power Shell:

 $Folder="C\EPMMigration"
foreach ($deployedSolution in Get-SPSolution)
{
         $id=$deployedSolution.SolutionID
         $title=$deployedSolution.Name
         $fileName=$deployedSolution.SolutionFile.Name
         $deployedSolution.SolutionFile.SaveAs("$Folder\$fileName")
}
Read More

Friday, June 30, 2017

View SQL table schema or definition

Leave a Comment
To view table schema definition one option is to right click table name view in design mode, other simple option is to view it through following query:

sp_help 'table_name'

It shows following:

  • When table/object is created & its owner
  • DDL of table (column name & its type & other definition details)
  • Identity, indexes, contraint & foreign key this table/object is reference as
Read More

Temp path is too long while publishing website project

Leave a Comment
While publishing my asp.net mvc website I got following error:

Issue:

ASPNETCOMPILER(0,0): Error ASPRUNTIME: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. 5>

Solution:

For me following solution works:


  • Go to web project folder e.g D:\Projects\SomeProject
  • Then go to Properties\PublishProfiles folder.
  • Open profile file in some editor i.e. profile_name.pubxml (not the file with *.pubxml.user)
  • Add following under <PropertyGroup> tag
  • <AspnetCompileMergeIntermediateOutputPath>c:\SomeShortTempPath\</AspnetCompileMergeIntermediateOutputPath> 
  • Save file & publish it again, it works like charm
  • Happy development




Read More

Friday, January 20, 2017

Encrypting & Decrypting connectionString in web.config

Leave a Comment
To cypher connection details at web/app configuation file I use following aspnet_regiis

To Encrypt:

aspnet_regiis.exe -pc "connectionStrings" -app "/BiztalkMicroService" 



To Decrypt:

aspnet_regiis.exe -pd "connectionStrings" -app "/BiztalkMicroService" 
Read More

Thursday, August 19, 2010

How to write a simple WCF service

Leave a Comment
These are series of windows communication foundation articles, in which I will show you how I learn from making a simple wcf service & then host it at iis, windows services, was & use different sort of bindings etc.

I have written a simple WCF Service Library and named it EmployeeServiceLibraryI have renamed the Interface & implanted class as shown above. First I made the IEmployeeService & defined OperationContract, DataContract & DataMember.

Now for the newbie, a question will come into the mind what are these hacks, so let me give a brief overview of these terminologies:

http://msdn.microsoft.com/en-us/library/ms735119%28VS.90%29.aspx

Then I have to remove the code available with in EmployeeService.cs by default & to implement IEmployeeService.cs I will do as follows:

It will give me following screen:
I have to add following variables:As I need to get data from AdventureWorks DB, do definitely I need my application to talk to SQL Server, so I follow it like this:

I choose properties of EmployeeWCFServiceLibraryProject & then choose settings. As there is no setting file is there so I have choose to create one option.

I gave it name AdventrueWorksConnectionString & choose type as connection string. From the value section, I choose my DB.

Now it is time to do a little bit of coding. I have to implement the ListEmployee method of IEmployeeService Interface to fetch data from Employee table of AdventureWorks DB.

Moreover I have to add System.Data & System.Data.SqlClient namespace to talk to DB. Following code snipets I used to fetch data for employee:

public ListEmployee> ListEmployee()

{

employees = new ListEmployee>();

using (var cnn = new SqlConnection(

Properties.Settings.Default.AdventureWorksConnectionString))

{

using (var cmd = new SqlCommand(

"Select EmployeeID, Title " +

"From Employee Order by EmployeeID", cnn))

{

cnn.Open();

using (SqlDataReader EmployeeReader =

cmd.ExecuteReader())

{

while (EmployeeReader.Read())

{

employee = new Employee();

employee.EmployeeID=

EmployeeReader.GetString(0);

employee.EmployeeTitle =

EmployeeReader.GetString(1);

employees.Add(employee);

}

}

}

}

return employees;

}

Then I use following code to fetch contact details for each employee:

public EmployeeDetail GetEmployeeDetails(string contactID)

{

employeeDetail = new EmployeeDetail();

using (var cnn = new SqlConnection(

Properties.Settings.Default.AdventureWorksConnectionString))

{

using (var cmd = new SqlCommand(

"select ContactID, FirstName, " +

"LastName, EmailAddress from Person.Contact " +

"where ContactID= @contactID order by ContactID", cnn))

{

cmd.Parameters.Add(new SqlParameter("@contactID", contactID));

cnn.Open();

using (SqlDataReader ContactReader =

cmd.ExecuteReader())

{

while (ContactReader.Read())

{

employeeDetail.ContactID =

ContactReader.GetString(0);

employeeDetail.EmployeeFirstName =

ContactReader.GetString(1);

employeeDetail.EmployeeLastName =

ContactReader.GetString(2);

employeeDetail.EmployeeEmail =

ContactReader.GetString(3);

}

}

}

}

return employeeDetail;

}

Then finally I implement the SaveChanges method as follows:

public bool SaveChanges(string contactID, string employeeFirstName, string employeeLastName,

string employeeEmail)

{

using (var cnn = new SqlConnection(

Properties.Settings.Default.AdventureWorksConnectionString))

{

using (var cmd = new SqlCommand(

"update Person.Contact " +

"set FirstName= @FirstName, " +

"LastName= @LastName, " +

"EmailAddress= @EmailAddress " +

"where ConatctID= @conatctID", cnn))

{

cmd.Parameters.Add(new SqlParameter(

"@FirstName", employeeFirstName));

cmd.Parameters.Add(new SqlParameter(

"@LastName", employeeLastName));

cmd.Parameters.Add(new SqlParameter(

"@EmailAddress", employeeEmail));

cmd.Parameters.Add(new SqlParameter(

"@conatctID", contactID));

cnn.Open();

numRowsChanged = (int)cmd.ExecuteNonQuery();

}

}

return (numRowsChanged != 0);

}

Now all set to go, its time to test our WCF Service, If I run the application, wcf service host will host our service & show us wcf test client where we can test our service.If I click ListEmployee() function & then click invoke, I will get a formatted list of employee table.Now our WCF Service is ready to be used & can be hosted in IIS, Windows service or WAS.

Read More

Tuesday, August 17, 2010

Export data from SQL Server to notepad

Leave a Comment

Last week during a training session, one of trainee raised a simple question. “Is there any

easy method to export data from sql server to notepad file”, b/c that poor fellow has been copy pasting it in the recent past. So I thought might be some more guys are there to find that simple answer. So I follow these simple steps:

As clearly shown in below picture I opened Import & export Wizard


From Choose data source section I choose AdventureWorks db. For the sake of simplicity I don’t change the default attributes.



In choose destination step, I have choosen flat file destination from destination drop down list, give it name C:\HumanResouceShift.txt and checked column names checkbox to get columan names as well.

In specify table copy or query, I choose first option due to make it simple enough for a power use to export the date, else by choosing second option, I can write my own tsql query to extarct data from destination

In next step in the wizard which is to configure flat file destination I choose HumanResources.Shift table.

I can choose from available option to put delimeters within column as well as b/w rows. But in this case I choose default options.


In final step which is Save & Run package, I choose run immediately. (In future blogs I will wirte in detail about saving it as SSIS pacakge & its protection level.

If everything goes well execution successful then I should have a file at my C: drive which I choose as my destination


Read More