I am trying to recycle the aws app pool remotely using below syntax
using (DirectoryEntry appPoolEntry = new DirectoryEntry(
"IIS://" + appPoolModel.ServerName + "/W3SVC/AppPools/"+appPoolModel.AppPoolName))
{
appPoolEntry.Invoke("Recycle", null);
appPoolEntry.Close();
}
But i am getting this below error
System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable.
For aws server i am using the server name as follows
"ec2-[Server Public IP].compute-1.amazonaws.com"
There couple of reason for this.
One obivious reason that shown in error that RPC server is actually not running.
If RPC server is running you have to check the firewall port open for RPC.
http://support.microsoft.com/kb/178517
Context of user in which your code is executed. Support you run in context of user1 and it does not have permission for DirectoryEntry object then it might fail.
if This is not possible then try to do it via Remote Powershell.
https://social.technet.microsoft.com/Forums/windowsserver/en-US/b24d5b03-343c-47b5-937e-aa47664cdfb2/how-can-i-restart-an-iis-webapppool-on-a-remote-server-in-powershell?forum=winserverpowershell
Related
I the following piece of code, and it works perfectly when it is run on a machine located in the same domain as the one in which is the remote server is.
However, if I run the same code on a machine which can reach the remote server, but is not in the same domain, then I get the following exception:
UnauthorizedAccessException
Retrieving the COM class factory for remote component with CLSID
{2B72133B-3F5B-4602-8952-803546CE3344} from machine [***SERVER_HOSTNAME***] failed
due to the following error: 80070005 [***SERVER_HOSTNAME***].
The exception is thrown by the call to GetWebConfiguration
It seems it's a question of my current credentials not being known on the remote server.
Question: How can I open a remote connection with custom credentials that are known remotely?
Code:
var serverManager = ServerManager.OpenRemote(serverName);
Configuration config = serverManager.GetWebConfiguration(locationPath);
ConfigurationSection accessSection = config.GetSection("system.webServer/security/access");
I am trying to create a remote connection to an exchange Powershell hosted on IIS 8.5 - Windows Server 2012 R2.
Here's my code :
var connInfo = new WSManConnectionInfo(
new Uri("https://xxx/PowerShell"),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
credentials);
It look like the Microsoft's Schemas url is not valid anymore. If I navigate to http://schemas.microsoft.com/powershell/Microsoft.Exchange, I have this :
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
And when I try to open my connection, I have this error :
Connecting to remote server failed with the following error message : The WinRM client received an HTTP bad request status (400), but the remote service did not include any other information about the cause of the failure.
Is it possible the url changed ? I trid to find a topic about it, but I found no trace of a change...
The schema uri doesn't have to be 'valid' in the sense you don't have to be able to navigate to it. I know I'm not explaining it properly but it's more a reference than a valid location.
The error you're receiving is actually referring to the uri you have for your Exchange Server. If you aren't connecting to an Exchange Server the connection will error.
I have the credentials to access a server in a local network - a network that is behind a proxy. And that server is running a SQL Server 7.0 database. The database is configured to use Windows authentication for log in.
I use the Remote Desktop Connection to access the server, put in the credentials, and when inside I open the Query Analyser, select log in with Windows authentication and then I query the DB.
But, now I need a .NET C# program to access the database from my machine, remotely. I have checked for a TCP/IP connection on port 1433 and it's open. However, with the following code, I cannot open a connection to the remote database.
SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder();
connStringBuilder["Trusted_Connection"] = false;
connStringBuilder["user id"] = "<domain>\\<user>";
connStringBuilder["password"] = "<pass>";
connStringBuilder["Database"] = "<db>";
connStringBuilder["Server"] = "\\\\<servername>\\MSSQLServer,1433";
connStringBuilder["Connection Timeout"] = "30";
SqlConnection myConn = new SqlConnection(connStringBuilder.ConnectionString);
try
{
myConn.Open();
// success
Console.WriteLine("Connection Opened");
}
catch (Exception e)
{
// failed
Console.WriteLine("Connection Failed");
Console.WriteLine(e.ToString());
}
The servername field is the same text I put in the Remote Desktop Connection tool, as it is with the user id and password fields after a connection is established (normal log on with Windows Server 2000).
Also, with the SSMS (SQL Server Management Studio) I cannot connect to the instance, however with Windows Explorer I can browse the server's drives with \\servername\e$ (for example).
Thank you in advance!
EDIT 1
I believe the problem is go through the remote machine log in, but I have no idea how to do that. I tested on a local db on my machine and the program works like a charm.
The error message from the exception e is the following, weather with true or false on the Trusted Connection:
System.Data.SqlClient.SqlException: A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that SQL Server is
configured to allow remote connections. (provider: SQL Network Interface, error: 25 -
Connection string is not valid)
at .... etc
EDIT 2
The steps I take to log on to the machine using some credentials are the following:
I first put in the server name as in "MACHINE33" (without quotes)
Remote Desktop Connection
And then I put the credentials \ as in "me\johndoe"
Credentials to access the remote machine
In the end the database is accessed using the windows authentication used to access the machine.
If you are using integrated authentication then the value for trusted connection should be either 'true' or 'sspi', not false. If 'true', any user id and password you specify on the connection string will be ignored so might as well not set them if you are intending to use the credentials for the currently logged in user (or the AppPool user if a web app, or the service user if a windows service etc.).
Are you using a named SQL Server instance? If so, a dynamic port is used, not 1433. You would need to either configure SQL Server to use a specific port for the named instance, or not specify a port.
"Login failed for user" when specifying default port
I have asked the systems administrator, this morning, and he told me that the database cannot be accessed from the outside, even though there is a TCP/IP configuration on port 1433 (checked under Server Network Utility for SQL Server 7.0). The reason is that the whole network is behind a proxy that checks all incoming requests and prevents the ones not coming from the tools specified (i.e. Remote Desktop Connection).
Since what I want is to migrate some fields from the structure of the old database to a new one, used by a new system, the solution is:
Access the remote machine, create a backup of the database, access the files through mapping the network drive, copy the backup files to your machine, create a local database and restore the backup to your new local database.
It's not the most elegant way, but it's the only way. And as an advice, first ask the systems administrator if you're behind a network full of proxies because it can save you a lot of headaches.
Thank you and sorry for the whole trouble.
I have written a windows service in C# to automatically poll an exchange mailbox using EWS.
On my development machine, which is connected to the exchange server network via VPN, it works perfectly.
On the target server the EWS is returning:
Request failed. The remote server returned an error: (401) Unauthorized.(The remote server returned an error: (401) Unauthorized.)
On the same server, I can connect to the EWS URL via a browser using the same credentials as are being provided to the service.
The credentials are provided in the app.config file, and I have triple checked that they are the same on the target server as my development machine.
What could be causing this?
Well as it turned out the issue was that this
_ews.Credentials = new NetworkCredential(Settings.Username, Settings.Password); // Username in the form "domainname\username"
should have been this
_ews.Credentials = new NetworkCredential(Settings.Username, Settings.Password, Settings.Domain); // Domainname and username separate
For some reason the first line worked externally over a VPN but not internally on the domain network itself.
A bit of background. I work for a corporation that has a global WAN. External users connect to it through a VPN and must be connected to it in order to have access to their emails and, of course, shared network directories.
I have a .Net application that is published and installed from our website using ClickOnce. User's who both do and do not work for the company have access to this application and it sends requests to a web service that is also published to the web server.
For reasons outside the scope of this question, when a user attempts to log into the application they should connect to the web service server by explicitly referencing the the computer name of the server (i.e. http://**server**/webservice/ws.asmx.) If a user is not connected to our WAN, they need to access it through our web address (i.e. https://**www.companywebsite.com**/webservice/ws.asmx.)
I know how to dynamically set the associated URL with the web service. My problem is that I can't think of an fast, reliable and easy way to test for the WAN connection.
Initially I tried to send a ping request (using the .Net Ping class) to the server with a rather short timeout. However, calling a ping operation against the server, when not connected to the WAN, returns an exception that states
An exeception occurred during the Ping request.
Below is the code associated with the property that tests for the WAN connection. It's simple but it keeps giving me above message when I test this off of our network.
public static bool ConnectedToWAN
{
get
{
try
{
Ping ping = new Ping();
PingReply reply = ping.Send("server", 2000);
return reply.Status == IPStatus.Success;
}
catch (Exception e)
{/* ' An exeception occurred during the Ping request.' */};
}
I would prefer not returning my connection state based off of the exception that I'm getting. Rather, I'd make an explicit call to the network that can validate the connection.
One quick note, I can't check the user's IP. Some of our users work for other organizations that have there own WAN. Since I'm checking their IP within a .Net WinForms application there is a chance that their IP address may be associated with their WAN. Instead, I need to check and see if they are specifically connected to our WAN, not just any WAN.
How can I do this?
I think the question is you need to resolve the host name if there are connected within company network rather than public accessible internet.
if that is the case, you can use DNS.BeginGetHostEntry and using asynchronous method to get the domain name system for specified host computer.
e.g
var host = '**Internal Server Name**';
Boolean isWANConnected = false;
String ConnectMessage ;
AsyncCallback callBack = new AsyncCallBack(GetHostName);
Dns.BeginGetHostEntry(host, callBack, host);
static void GetHostName(IAsyncResult result)
{
string hostname = (string)result.AsyncState;
try
{
IPHostEntry host = Dns.EndGetHostEntry(result)
ConnectMessage = host as String;
}
catch(SocketException e)
{
isWANConnected = false;
ConnectMessage = e.Message;
}
}
Can a user not on the WAN resolve that server IP? If not, you can use a DNS query to determine where you are.