Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Service : System.Web.Services.WebService
- {
- public TicketHeader Ticket;
- public DataSet ds;
- private string machine = "pcName";
- public string userName = "********";
- public string password = "*********";
- public IntPtr token;
- public WindowsImpersonationContext impersonationContext;
- [DllImport(@"D:WindowsSystem32advapi32.dll")]
- public static extern bool LogonUser
- (string lpszUserName, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out int phToken);
- public void Login()
- {
- int returnedToken;
- if (LogonUser(userName, machine, password, 3, 0, out returnedToken))
- {
- token = new IntPtr(returnedToken);
- }
- }
- [WebMethod]
- public DataSet GetDataSet(string id)
- {
- DataSet ds = null;
- Login();
- impersonationContext = WindowsIdentity.Impersonate(token);
- SqlConnection conn = null;
- SqlDataAdapter da = null;
- try
- {
- string sql = "Select * from Table";
- conn = new SqlConnection(@"Data Source=.SQLEXPRESS; Integrated Security=True;" +
- @"AttachDbFilename=|DataDirectory|ORLDatabase.mdf;");
- conn.Open();
- da = new SqlDataAdapter(sql, conn);
- ds = new DataSet();
- da.Fill(ds, "Table");
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- finally
- {
- if (conn != null)
- conn.Dispose();
- }
- impersonationContext.Undo();
- return ds;
- }
- }
Add Comment
Please, Sign In to add comment