Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Monday, March 26, 2012

PLEASE HELP - Accessing Web Services through Windows App

I am running a vb.net application that is using the Web Service to
issue Update Snapshot. There is a Windows account we are using as a
Service account that has the proper permissions to Generate Events.
The application is running on AutoSys on a 2003 server. I have
confirmed that it will run under this users credentials manually by
logging into the server as the user and firing the app. It works
without a problem. This was using Default Credentials.

The AutoSys job is configured to run under this user's credentials.
There are three ways I have executed this application

>>Through AutoSys running as the user with the proper permissions (this is in place of a Local Service account which is default for AutoSys. This windows user has local admin permissions on the AutoSys server as well as Generate Event permission as confirmed before)
>>By logging into the server as Administrator and executing the app with "Run As..." set to the Windows ID
>>By switching to new.NetworkCredentials and passing the hardcoded username/pass/domain

For all of the above scenarios - it fails

The ONLY time it successfully issues UpdateSnapshot is when I am
logged in to the server as the user in question. In ALL other
instances detailed above it fails and the following comes out of the
event log

"Line 1: Incorrect syntax near 'MyDomainName'.

I have no idea why it is choking on the Domain Name in all three of
those scenarios.

Do I need to impersonate that user through code when passing the Web
Service credentials?

PLEASE PLEASE PLEASE help - I need to wrap this up. ANY HELP WOULD BE
GREATLY APPRECIATED

Could you show a sample of your code? Syntax error indicates compilation/parsing error. AutoSys method #2 or #3 sound like they should be workable.

Thank you.

|||

I was wrong (partially) - the error I am referring to in the original post is being caused by my attempt to trap the error and write it to a log table in SQL Server. The error is actually as follows

The permissions granted to user 'mydomain\myuser' are insufficient for performing this operation

The fact that there are single quotes in the error is causing a syntax error in my SQL statement.

So - the actual user still does not have the permissions needed to issue UpdateSnapshot. I have confirmed with the Administrators that the user is in a role on the server that contains Generate Events and is also a Browser on all reports on the server.

I did this before in a previous environment and it worked perfectly. Can anyone definitively tell me what permissions are required in order to do things like UpdateSnapshot, FireEvent, CreateSubscription? I thought Generate Events was all that was needed.

During testing I was using my ID to do it and it worked. So I thought I could just create a dummy account and give it the permissions. I am stumped

|||

For update snapshot, you need Execute permission on the report you operate on. You can get it from Manage Report or Manager History task.

You are right for FireEvent you need Generate Event task (which contains generate event permission).

For CreateSubscription, you need either CreateSubscription or CreateAnySubscription permission. It is in "Manage Individual Subscriptions" or "Manage Any subscriptions" task.

|||

Thank you - I did discover that I was looking at the wrong permissions for Updating a Snapshot. The problem I originally had raises and interesting question. How do I handle the SOAP exception with the single quotes in it if I want to write that to a SQL Table? Seems odd that an error would contain single quotes!

|||This is the way we choose to mark the name (RS item name, username, etc.). I guess you can do a string replacing before you insert into your table.sql

Wednesday, March 21, 2012

Please can someone point out whats wrong with my code

Hi,

I have code on a page to update one table and insert info into another, but I cant make it work. I am new to coding and i think there are many mistakes. Please can someone pick out a few that need to be changed for the page to work.

Code:

private bool ExecuteUpdate(int quantity)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "ConnectionString";

con.Open();

SqlCommand command = new SqlCommand();
command.Connection = con;
TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");
Label labname = (Label)FormView1.FindControl("Label3");
Label labid = (Label)FormView1.FindControl("Label13");

command.CommandText = "UPDATE Items SET Quantityavailable WHERE productID='@.productID' = " + TextBox1.Text +

command.ExecuteNonQuery();
return true;
con.Close();
}

private bool ExecuteInsert(String quantity)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "ConnectionString";

con.Open();

SqlCommand command = new SqlCommand();
command.Connection = con;
TextBox TextBox1 = (TextBox)FormView1.FindControl("TextBox1");
Label labname = (Label)FormView1.FindControl("Label3");
Label labid = (Label)FormView1.FindControl("Label13");

command.CommandText = "INSERT Transactions SET Usersname = @.UserName" +
"; INSERT Transactions SET Itemid WHERE productID='@.productID' = @.productID; INSERT Transactions SET itemname = @.Itemsname" +
"; INSERT Transactions SET Date WHERE productID='@.productID' = " + DateTime.Now.ToString() +
"; INSERT Transactions SET Qty WHERE productID='@.productID' = " + TextBox1.Text;
command.Parameters.Add("@.UserName", System.Web.HttpContext.Current.User.Identity.Name);
command.Parameters.Add("@.Itemsname", labname.Text);
command.Parameters.Add("@.productID", labid.Text);
command.ExecuteNonQuery();
return true;
con.Close();
}

protected void Button2_Click(object sender, EventArgs e)
{
TextBox TextBox1 = FormView1.FindControl("TextBox1") as TextBox;
ExecuteUpdate(Int32.Parse(TextBox1.Text) );
ExecuteInsert(Int32.Parse);
}

Current error message is:

The best overloaded method match for 'detailproview.ExecuteInsert(string)' has some invalid arguments

to

Line 74: ExecuteInsert(Int32.Parse);
 
Thanks if someone can help!
Jon 

Hi,

The best way for you to see why it is not working is to debug your code and check the values in the object using Immediate window or pointing the mounse on the objects after value is assigned.

Maybe you are not getting the id that you are using in the WHERE lause of your update statement. Make sure you are getting valid id and that it exists in database.

Finally you are calling return true before closing the connection, first close the connection than return a value.

|||


Int32.Parse is a method and you need to pass in an argument to it, the one string which you want to conevrt to an int, like you are doing it here:

ExecuteUpdate(Int32.Parse(TextBox1.Text) );

Hope this helps,

Vivek

|||

Hi,

Thanks both great to help me iron out bugs.

I will put up a new post with the latest set of error messages!

Cheers

Jon