How I can get specific values from the following URL I need to get only 3 values
http://earnprofitclickint.com/UserWorking/Successfull.aspx?lr_paidto=U9925362&lr_amnt=2.00&lr_currency=LRUSD&lr_store=http%3A%2F%2Fwww.earnprofitclickint.com&lr_merchant_ref=&lr_paidby=U3563444&lr_fee_amnt=0.00&lr_transfer=143636187&lr_timestamp=2013-12-05+18%3A31%3A33&ctl00%24contentplaceholder1%24amount=&ctl00%24contentplaceholder1%24id=70&ctl00%24contentplaceholder1%24txtamount=+2&ctl00%24contentplaceholder1%24username=networker&lr_encrypted=04E20ADA982A2AF9C1C64DB3C1601BA596373E22D7B4D21813A51C43DC0198CD&lr_encrypted2=59C8269D431F915360F3B8179EC95181D8C458AB91D72AF3DFC1DC0DFDAC4F64
I want to get 3 values from the above URL return from Liberty Reserve Website and want to insert these three values to database using LINQ TO SQL
I need to get the following values
r_amnt=2.00 ID=70 username=networker
I have written the code in page load to get the above values when the response come and Redirect to my successful page:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ID.Value = Request.QueryString["id"].ToString();
UserName.Value = Request.QueryString["username"].ToString();
Amount.Value = Request.QueryString["lr_amnt"].ToString();
SaveLocalHistory();
Divmessage.Visible = true;
}
}
public void SaveLocalHistory()
{
MLMDataContext db = new MLMDataContext();
UsersInvestement pd = new UsersInvestement();
pd.Amount = Convert.ToDouble(Amount.Value);
pd.UserId = Convert.ToInt32(ID.Value);
pd.UserName = UserName.Value;
pd.Description = "This amount has been received From LR";
pd.IncomeTypeId = 4;
pd.CreatedDate = DateTime.Now.Date;
db.UsersInvestements.InsertOnSubmit(pd);
db.SubmitChanges();
}
This is a manual change in the URL:
http://earnprofitclickint.com/UserWorking/Successfull.aspx?lr_paidto=U9925362&lr_amnt=2.00&lr_currency=LRUSD&lr_store=http%3A%2F%2Fwww.earnprofitclickint.com&lr_merchant_ref=&lr_paidby=U3563444&lr_fee_amnt=0.00&lr_transfer=143636187&lr_timestamp=2013-12-05+18%3A31%3A33&ctl00%24contentplaceholder1&amount=&ctl00%24contentplaceholder1&id=70&ctl00%24contentplaceholder1%24txtamount=+2&ctl00%24contentplaceholder1&username=networker&lr_encrypted=04E20ADA982A2AF9C1C64DB3C1601BA596373E22D7B4D21813A51C43DC0198CD&lr_encrypted2=59C8269D431F915360F3B8179EC95181D8C458AB91D72AF3DFC1DC0DFDAC4F64
If I change it manually then it works. Any idea?
Your parameter names are not username and id, they are ctl00$contentplaceholder1$username for username and ctl00$contentplaceholder1$id for id
Since %24 when URLDecode gives $ , you need to do the corresponding replacements too.
Try this:
ID.Value = Request.QueryString["ctl00$contentplaceholder1$id"].ToString();
UserName.Value = Request.QueryString["ctl00$contentplaceholder1$username"].ToString();
Amount.Value = Request.QueryString["r_amnt"].ToString();
and it should work. Let me know otherwise! :)
I am fairly certain that the query string values are case sensitive, meaning that this code
ID.Value = Request.QueryString["ID"].ToString();
UserName.Value = Request.QueryString["UserName"].ToString();
Amount.Value = Request.QueryString["lr_amnt"].ToString();
should probably be in this form
ID.Value = Request.QueryString["id"].ToString();
UserName.Value = Request.QueryString["username"].ToString();
Amount.Value = Request.QueryString["r_amnt"].ToString();
if you wanted to pull out "r_amnt=2.00 id=70 username=networker"
As an aside, note that you never dispose of your database context. This can be dangerous in that it is possible your connection will not close for a very long time, I would suggest doing this instead:
using( MLMDataContext db = new MLMDataContext() )
{
UsersInvestement pd = new UsersInvestement();
pd.Amount = Convert.ToDouble(Amount.Value);
pd.UserId = Convert.ToInt32(ID.Value);
pd.UserName = UserName.Value;
pd.Description = "This amount has been received From LR";
pd.IncomeTypeId = 4;
pd.CreatedDate = DateTime.Now.Date;
db.UsersInvestements.InsertOnSubmit(pd);
db.SubmitChanges();
}
The using statement ensures that Dispose is called on the DataContext (which inherits from IDisposable) and will properly close the connection once the actions complete.
Related
Is there a way by which I can trigger a SSRS subscription (Time based) whenever there is an event like file created in a shared folder? Can we do it with powershell or C#?
Is there a out of box feature available in SSRS (though I don't think there is any)?
I am using SQL Server 2008 R2.
Yes, we do something like this here. You can use the FireSubscription function of the Reporting Services web services to trigger a subscription. Here's a detailed explanation of how to set it up:
Firing a Reporting Services Subscription
You can use the FileSystemWatcher to tell when your file is dropped and then fire the subscription off. It's asynchronous though so you don't get notification if the report was sent successfully... only that it was successfully queued up. Also you first modify the parameters of the subscription before you fire it, so you have to make sure that you don't have more than one program to trigger the subscription or it might end up tripping over itself.
Another slightly more complicated way to do it is to use the Render function to generate a report and then have your program manage the emailing.
Render Function
This way you don't have to create a dummy subscription and you'll know immediately if it was sent successfully with the correct parameters.
One final note... if you have the Enterprise Edition (which you probably don't), it comes with Data Driven Report Subscriptions, which you could use to trigger a subscription:
Creating a Data-Driven Subscription
Here i have used timely subscription , i had requirement to generate report
on some button click, so i created subscription which will fire after one minute and generate PDF report.
And I got all help from this article :
http://odetocode.com/articles/114.aspx
You need to add webservice reference of webservice provided by SSRS
http://mymachine/ReportServer/ReportService2010.asmx
Here #"\MyMachineName\Share", is path where my pdf was stored
(PATH:The folder path or UNC file share path to which to save the report.
https://msdn.microsoft.com/en-us/library/ms154020.aspx)
So you can call generate subscription as per your need on file created.
using Test_WebProject.ReportService2010;
private static ExtensionSettings GetExtensionSettings()
{
ParameterValue[] extensionParams = new ParameterValue[7];
for (int i = 0; i < extensionParams.Length; i++)
extensionParams[i] = new ParameterValue();
extensionParams[0].Name = "FILENAME";
extensionParams[0].Value = "Test1#TimeStamp";
extensionParams[1].Name = "FILEEXTN";
extensionParams[1].Value = "true";
extensionParams[2].Name = "PATH";
extensionParams[2].Value = #"\\MyMachineName\Share";
extensionParams[3].Name = "RENDER_FORMAT";
extensionParams[3].Value = "PDF";
extensionParams[4].Name = "WRITEMODE";
extensionParams[4].Value = "None"; //"Overwrite ";// "AutoIncrement";
extensionParams[5].Name = "USERNAME";
extensionParams[5].Value = "gmd";
extensionParams[6].Name = "PASSWORD";
extensionParams[6].Value = "password123";
ExtensionSettings extensionSettings = new ExtensionSettings();
extensionSettings.Extension = "Report Server FileShare"; // EXTENSION_FILESHARE;
extensionSettings.ParameterValues = extensionParams;
return extensionSettings;
}
static void generateSubscription()
{
string report = #"/MyReports/TestSSRSSubscrptionReport";
string description = "My Test subscription2010";
string eventType = "TimedSubscription";
ExtensionSettings extSettings = GetExtensionSettings();
List<ReportService2010.ParameterValue> parameters = new List<ReportService2010.ParameterValue>();
parameters.Add(new ReportService2010.ParameterValue() { Name = "EmployeeKey", Value = "9" });
parameters.Add(new ReportService2010.ParameterValue() { Name = "SelectedColumn", Value = "EmployeeKey" });
parameters.Add(new ReportService2010.ParameterValue() { Name = "ParamSelectedColumns", Value = "FirstName" });
parameters.Add(new ReportService2010.ParameterValue() { Name = "ParamSelectedColumns", Value = "LastName" });
NetworkCredential credentials = new NetworkCredential("gmd", "password123");
ReportService2010.ReportingService2010 rs = new ReportService2010.ReportingService2010();
rs.Credentials = credentials; // System.Net.CredentialCache.DefaultCredentials;
DateTime topDatetime = DateTime.Now;
topDatetime = topDatetime.AddMinutes(1);
string scheduleXml = "<ScheduleDefinition><StartDateTime>";
scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
scheduleXml += "</StartDateTime></ScheduleDefinition>";
string sid = rs.CreateSubscription(report, extSettings, description, eventType, scheduleXml, parameters.ToArray());
}
You could create a windows service that uses FileSystemWatcher (https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx) and then just trigger your job on the changed event.
I have a project that inserts personal information to a table and details into another table. But sometimes personal information cannot be recorded, however details are recorded. As below code part, firstly personal information are inserted, then details. But sometimes personal information doesn't get saved and userId returns 0, So details are saved. I don't know why it doesn't work. Any idea?
public int ConferenceIdyeGoreKisiBilgileriniKaydet(string orderId)
{
KisiselBilgilerBal kisiBilgileri = (KisiselBilgilerBal)Session["kisiselBilgilerSession"];
registrationCode = GenerateGeristrationCode();
string toplamMaliyet = Session["toplamOdeme"].ToString();
PersonalInformation.SavePersonalInformations(kisiBilgileri, registrationCode,conferenceName);
int userId = AuthorPaperDetaylari.AdVeSoyadaGoreIdGetir(kisiBilgileri.f_name, kisiBilgileri.l_name);
AuthorPaperDetaylari.SaveAuthorPaperDetails(authorPaperDetay, userId); // save details via userId.
return userId;
}
This method saves personal information.
public static void SavePersonalInformations(KisiselBilgilerBal kisiBilgileri,string registrationCode,string conferenceName)
{
try
{
string cs = ConfigurationManager.AppSettings["SiteSqlServer"];
DBDataContext db = new DBDataContext(cs);
DBpersonalInformation personalInfo = new DBpersonalInformation();
personalInfo.f_name = kisiBilgileri.f_name;
personalInfo.l_name = kisiBilgileri.l_name;
personalInfo.university_affiliation = kisiBilgileri.university_affiliation;
personalInfo.department_name = kisiBilgileri.department_name;
personalInfo.address1 = kisiBilgileri.address1;
personalInfo.address2 = kisiBilgileri.address2;
personalInfo.city = kisiBilgileri.city;
personalInfo.state = kisiBilgileri.state;
personalInfo.zipCode = kisiBilgileri.zipCode;
personalInfo.country = kisiBilgileri.country;
personalInfo.phone = kisiBilgileri.phone;
personalInfo.email = kisiBilgileri.email;
personalInfo.orderId = kisiBilgileri.orderId;
personalInfo.registrationCode = registrationCode;
personalInfo.date = DateTime.Now;
personalInfo.conferenceName = conferenceName;
db.DBpersonalInformations.InsertOnSubmit(personalInfo);
db.SubmitChanges();
}
catch (Exception)
{
}
}
This method saves details
public static void SaveAuthorPaperDetails(AuthorPaperDetailsBal authorPaperDetay, int userId)
{
try
{
string cs = ConfigurationManager.AppSettings["SiteSqlServer"];
DBWebDataContext db = new DBWebDataContext(cs);
DBAuthorPaperDetail authorPaperDetail = new DBAuthorPaperDetail();
authorPaperDetail.paper_title = authorPaperDetay.paperTitleDetails;
authorPaperDetail.conference_maker_id = authorPaperDetay.confMakerId;
authorPaperDetail.additional_paper_title = authorPaperDetay.additionalPprTtle;
authorPaperDetail.areYouMainAuthor = authorPaperDetay.mainAuthor;
authorPaperDetail.feeForFirstAuthorPaper = authorPaperDetay.registerFeeForFirstAuthor;
authorPaperDetail.feeForAdditionalPaper = authorPaperDetay.regFeeForAdditionalPape;
authorPaperDetail.feeForParticipCoAuthors = authorPaperDetay.regFeeForCoAuthors;
authorPaperDetail.userId = userId;
authorPaperDetail.firstCoAuthorName = authorPaperDetay.firstCoAuthor;
authorPaperDetail.secondCoAuthorName = authorPaperDetay.secondCoAutho;
authorPaperDetail.thirdCoAuthorName = authorPaperDetay.thirdCoAuthor;
authorPaperDetail.toplamOdeme = authorPaperDetay.toplamMaliyet;
db.DBAuthorPaperDetails.InsertOnSubmit(authorPaperDetail);
db.SubmitChanges();
}
catch (Exception)
{
}
}
I don't know why it doesnt work. Any idea?
...
catch (Exception)
{
}
Well, that explains pretty much everything... don't do this. Ever. The database layer is trying to tell you what the problem is, and you are sticking your fingers in your ears, hoping that'll make it go away. If I had to guess: maybe an occasional timeout due to being blocked by another SPID.
If you can't do anything useful or appropriate with an exception, just let it bubble to the caller. If it gets to the UI, tell the user about it (or just log the issue internally and tell the user "There was a problem").
Also, a LINQ-to-SQL data-context is IDisposable; you should have using statement around db.
In addition to Marc's answer... You are calling SubmitChanges twice. If you want atomic data storage, you should call it once. You can use relational properties to create an object graph, and submit the whole graph at once.
public void SaveParentAndChildren()
{
using (CustomDataContext myDC = new CustomDataContext())
{
Parent p = new Parent();
Child c = new Child();
p.Children.Add(c);
myDC.Parents.InsertOnSubmit(p); //whole graph is now tracked by this data context
myDC.SubmitChanges(); // whole graph is now saved to database
// or nothing saved if an exception occurred.
} //myDC.Dispose is called for you here whether exception occurred or not
}
I'm trying to re write a search from System.DirectoryServices to System.DirectoryServices.Protocol
In S.DS I get all the requested attributes back, but in S.DS.P, I don't get the GUID, or the HomePhone...
The rest of it works for one user.
Any Ideas?
public static List<AllAdStudentsCV> GetUsersDistinguishedName( string domain, string distinguishedName )
{
try
{
NetworkCredential credentials = new NetworkCredential( ConfigurationManager.AppSettings[ "AD_User" ], ConfigurationManager.AppSettings[ "AD_Pass" ] );
LdapDirectoryIdentifier directoryIdentifier = new LdapDirectoryIdentifier( domain+":389" );
using ( LdapConnection connection = new LdapConnection( directoryIdentifier, credentials ) )
{
SearchRequest searchRequest = new SearchRequest( );
searchRequest.DistinguishedName = distinguishedName;
searchRequest.Filter = "(&(objectCategory=person)(objectClass=user)(sn=Afcan))";//"(&(objectClass=user))";
searchRequest.Scope = SearchScope.Subtree;
searchRequest.Attributes.Add("name");
searchRequest.Attributes.Add("sAMAccountName");
searchRequest.Attributes.Add("uid");
searchRequest.Attributes.Add("telexNumber"); // studId
searchRequest.Attributes.Add("HomePhone"); //ctrId
searchRequest.SizeLimit = Int32.MaxValue;
searchRequest.TimeLimit = new TimeSpan(0, 0, 45, 0);// 45 min - EWB
SearchResponse searchResponse = connection.SendRequest(searchRequest) as SearchResponse;
if (searchResponse == null) return null;
List<AllAdStudentsCV> users = new List<AllAdStudentsCV>();
foreach (SearchResultEntry entry in searchResponse.Entries)
{
AllAdStudentsCV user = new AllAdStudentsCV();
user.Active = "Y";
user.CenterName = "";
user.StudId = GetstringAttributeValue(entry.Attributes, "telexNumber");
user.CtrId = GetstringAttributeValue(entry.Attributes, "HomePhone");
user.Guid = GetstringAttributeValue(entry.Attributes, "uid");
user.Username = GetstringAttributeValue(entry.Attributes, "sAMAccountName");
users.Add(user);
}
return users;
}
}
catch (Exception ex)
{
throw;
}
}
Also, if I want to fetch EVERY user in AD, so I can synch data with my SQL DB, how do I do that, I Kept getting max size exceeded, errors. I set the size to maxInt32... is there an "ignore size" option?
Thanks,
Eric-
I think that the standard way is to use System.DirectoryServices, not System.DirectoryServices.Protocol. Why do you want to user the later ?
Concerning your second question about the error message "max sized exceeded", it may be because you try to fetch too many entries at once.
Active Directory limits the number of objects returned by query, in order to not overload the directory (the limit is something like 1000 objects). The standard way to fetch all the users is using paging searchs.
The algorithm is like this:
You construct the query that will fetch all the users
You specify a specific control (Paged Result Control) in this query indicating that this is
a paged search, with 500 users per page
You launch the query, fetch the first page and parse the first 500 entries in
that page
You ask AD for the next page, parse the next 500 entries
Repeat until there are no pages left
I created a program a while ago using C# that does some automation for a completely different program, but found that I need to access data from a Lotus Notes database. The only problem is, I can only seem to figure out how to open the database by the server's name (using session.GetDatabase())... I can't figure out how to open it by Replica ID. Does anyone know how I would go about that? (I don't want my program going down every time the server changes.)
public static string[] GetLotusNotesHelpTickets()
{
NotesSession session = new NotesSession();
session.Initialize(Password);
// 85256B45:000EE057 = NTNOTES1A Server Replica ID
NotesDatabase database = session.GetDatabase("NTNOTES1A", "is/gs/gshd.nsf", false);
string SearchFormula = string.Concat("Form = \"Call Ticket\""
, " & GroupAssignedTo = \"Business Systems\""
, " & CallStatus = \"Open\"");
NotesDocumentCollection collection = database.Search(SearchFormula, null, 0);
NotesDocument document = collection.GetFirstDocument();
string[] ticketList = new string[collection.Count];
for (int i = 0; i < collection.Count; ++i)
{
ticketList[i] = ((object[])(document.GetItemValue("TicketNumber")))[0].ToString();
document = collection.GetNextDocument(document);
}
document = null;
collection = null;
database = null;
session = null;
return ticketList;
}
This code is working fine, but if the server changed from NTNOTES1A, then nothing is going to work anymore.
you'll need to use the notesDbDirectory.OpenDatabaseByReplicaID(rid$) method. To get the NotesDbDirectory, you can use the getDbDirectory method of the session
Set notesDbDirectory = notesSession.GetDbDirectory( serverName$ )
So you can use the code below to get a database by replicaID.
public static string[] GetLotusNotesHelpTickets()
{
NotesSession session = new NotesSession();
session.Initialize(Password);
Set notesDBDirectory = session.GetDbDirectory("NTNOTES1A")
// 85256B45:000EE057 = NTNOTES1A Server Replica ID
NotesDatabase database = notesDBDirectory.OpenDatabaseByReplicaID("85256B45:000EE057")
string SearchFormula = string.Concat("Form = \"Call Ticket\""
, " & GroupAssignedTo = \"Business Systems\""
, " & CallStatus = \"Open\"");
NotesDocumentCollection collection = database.Search(SearchFormula, null, 0);
NotesDocument document = collection.GetFirstDocument();
string[] ticketList = new string[collection.Count];
for (int i = 0; i < collection.Count; ++i)
{
ticketList[i] = ((object[])(document.GetItemValue("TicketNumber")))[0].ToString();
document = collection.GetNextDocument(document);
}
document = null;
collection = null;
database = null;
session = null;
return ticketList;
}
Unfortunately, this only solves half of your problem. I know you'd rather just tell Notes to fetch the database with a particular replicaID from the server closest to the client, just like the Notes Client does when you click on a DBLink or Bookmark. However, there is (or appears to be) no way to do that using the Notes APIs.
My suggestion is to either loop through a hard-coded list of potential servers by name, and check to see if the database is found (the OpenDatabaseByReplicaID method returns ERR_SYS_FILE_NOT_FOUND (error 0FA3) if the database is not found). If that's not a good option, perhaps you can easily expose the servername in an admin menu of your app so it can be changed easily if the server name changes at some point.
set database = new NotesDatabase("")
call database.OpenByReplicaID("repid")
I want to load the data into session so that when the next button is clicked in crystal report viewer then in should load the data from the datatable instead retrieving the data again from the database. Here goes my code...
ReportDocument rpt = new ReportDocument();
DataTable resultSet = new DataTable();
string reportpath = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString.Get("id") == "5")
{
string publication = Request.QueryString.Get("pub");
DateTime date = DateTime.Parse(Request.QueryString.Get("date"));
int pages = int.Parse(Request.QueryString.Get("pages"));
int sort = int.Parse(Request.QueryString.Get("sort"));
if (sort == 0)
{
reportpath = Server.MapPath("IssuesReport.rpt");
rpt.Load(reportpath);
DataTable resultSet1 = RetrievalProcedures.IssuesReport(date, publication, pages);
Session["Record"] = resultSet1;
}
DataTable report = (DataTable)Session["Record"];
rpt.SetDataSource(report);
CrystalReportViewer1.ReportSource = rpt;
I am trying this code but when i clicked the next button it gives me the error that invalid report source..i guess the session is null thats why its giving me this error.
Any sugesstions how can I solve this...
I think you'd want to use the Cache object with a unique key for each user instead of Session here.
Pseudo code:
var data = Cache["Record_999"] as DataTable;
if (data == null) {
// get from db
// insert into cache
}
SetDataSource(data);
The problem lies not in with using Session, it lies with the logic used to determine when to retrieve data. Session is the correct approach to use here as Cache is shared across requests - that is, User A would see the report User B just configured if User B was the first user to execute code that used Cache instead of Session.
if (!Page.IsPostBack)
{
if (Request.QueryString.Get("id") == "5")
{
string publication = Request.QueryString.Get("pub");
DateTime date = DateTime.Parse(Request.QueryString.Get("date"));
int pages = int.Parse(Request.QueryString.Get("pages"));
int sort = int.Parse(Request.QueryString.Get("sort"));
// fixed the statement below to key off of session
if (Session["Record"] == null)
{
reportpath = Server.MapPath("IssuesReport.rpt");
rpt.Load(reportpath);
Session["Record"] = RetrievalProcedures.IssuesReport(date, publication, pages);
}
rpt.SetDataSource((DataTable)Session["Record"]);
CrystalReportViewer1.ReportSource = rpt;
// ....
}
}
`Could it be that sort is not 0? If sort is not 0 and the user is accessing the page for the first time(Session["Record"] has not been set before) he might get the error.
might want to try:
if(sort==0 || Session["Record"] == null)
{
// do your magic
}