Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > CSV import View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 3/13/2012 10:17:58 PM
   
CSV import
Hi Guys,

I have imported Users in the database from a CSV with the help of Kentico Import toolkit.
It works fine.

Is there a way to run this process every night.
Like a cron job?

Our idea is to delete all the users from the database every night and add new users from a new CSV file.

Has anyone done this before or something similar?

Thanks
Gitesh Shah

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/14/2012 3:38:34 AM
   
RE:CSV import
Hello,

You can create a scheduled task for importing the users. I would recommend you to use our API for importing users on a regular basis instead of the Import toolkit.

Best regards,
Boris Pocatko

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 3/25/2012 4:07:01 PM
   
RE:CSV import
Hi Boris,

Thanks for the suggestion.

I have started working on it. But facing some issues on it. Your help would be appreciated.

I am trying to delete all the users and have used the below code. It deletes all the users which are having UserID between 1 to 10000 (except Administrator(UserID 53) and Public(UserID 65)).

Is there any better way of writing this thing?



private bool DeleteUser()
{

for (int i = 0; i < 10000; ++i)
{
// Get the user
UserInfo deleteUser = UserInfoProvider.GetUserInfo(i);
//UserInfo deleteUser = UserInfoProvider.GetUserInfo("Username");
//UserInfo deleteUser = UserInfoProvider.GetUserInfo(USERID);

// Delete the user
if ((deleteUser != null) && (i != 53) && (i != 65))
{
UserInfoProvider.DeleteUser(deleteUser);
}
}

return true;
}





Thanks
Gitesh Shah

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 3/26/2012 2:03:46 AM
   
RE:CSV import
Hello,

I would suggest you to get all the users with the following method:

UserInfoProvider.GetAllUsers();

Otherwise your code looks fine.

Best regards,
Boris Pocatko

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 3/26/2012 8:40:30 PM
   
RE:CSV import
Hi Boris,

After deleting some of the users it is giving me errrors in the event log(looks like timeout issue).

Below is the 2 event log messages:


Message: Thread was being aborted.
Stack Trace:
at SNIReadSync(SNI_Conn* , SNI_Packet** , Int32 )
at SNINativeMethodWrapper.SNIReadSync(SafeHandle pConn, IntPtr& packet, Int32 timeout)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at CMS.DataProviderSQL.DataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)
at CMS.DataEngine.GeneralConnection.RunQuery(QueryParameters query)
at CMS.DataEngine.GeneralConnection.ExecuteQuery(QueryParameters query)
at CMS.DataEngine.ConnectionHelper.ExecuteQuery(String queryName, QueryDataParameters parameters, String where)
at CMS.SiteProvider.UserInfoProvider.SetUserInfoInternal(UserInfo user)
at CMSAPIExamples_Code_Administration_Membership_Default.CreateUser()
at CMSAPIExamples_Controls_APIExample.Run()



Second error meesage:


Message: Request timed out.
Stack Trace:




Any ideas where I can increase the timeout value for this?

Thanks
Gitesh Shah

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 3/30/2012 10:27:37 AM
   
RE:CSV import
Are you running it within a request?
You may try to create a new thread for that task (see .NET documentation for instructions), or extend the request timeout in the web.config:

<httpRuntime executionTimeout="43200" maxRequestLength="2097151" ... />

the value is in seconds.

See also weblogs.asp.net/aghausman/archive/2009/02/20/prevent-request-timeout-in-asp-net

If your script is taking several minutes to execute and there are many concurrent users then consider changing the page to an Asynchronous Page.

Regards,
Zdenek