I have created a web service that accesses a database. Both the database and the webservice i.e. SQL server and IIS are on the same machine.
The problem is that when i access the webservice which in turn accesses the database on the server using my client, everything works fine.
But when i access it from other pc, i get Database error.
The same connectionstring ehich works fine while accessing the server does not open the connection while accessing the webservice remotely.
Any help appreciated.
[Edit]
When i access it on the server, i get the logs as per my requirement like this :
ConnectionString = Server=localhost\instancename;Database=dbname;Uid=uid;Pwd=pwd;
And when i access remotely, i get the logs like this :
ConnectionString = Server=localhost\instancename;Database=dbname;Uid=uid;Pwd=pwd;
ERROR:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> 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 Interfaces, error: 26 - Error Locating Server/Instance Specified)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at CMACLBilling.AuthenticationService.Service1.GetUser(String userName)
at CMACLBilling.BusinessControllers.UserBusinessController.Authenticate(String userName, String password, Int32& errorCode)
at CMACLBilling.LoginWindow.btnLogin_Click(Object sender, RoutedEventArgs e)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
As i guessed about your connection that you are providing wrong information:
Check your connection string:
ConnectionString = "Server=localhost\instancename;Database=dbname;Uid=uid;Pwd=pwd;"
and the error is Error Locating Server/Instance Specified- A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
localhost is refers to the your system on which you are working. If you access this from another computer then it will cause error.
Example as below help to configure correct connection string:
<connectionStrings>
<add name=”SampleConnectionString” connectionString=”Data Source=machinename\instancename;Initial Catalog=AdventureWorks;Integrated Security=SSPI;Min Pool Size=5;Max Pool Size=60;Connect Timeout=30″ providerName=”System.Data.SqlClient”/>
</connectionStrings>
and Connect via an IP address of your server
Server=190.190.200.100,1433;Network Library=DBMSSOCN;Initial
Catalog=myDataBase;User ID=myUsername;Password=myPassword;
or
Server=IISPCName or Server= IISPCName\InstanceName
When i do such functionality as you do copy the computer name from my Computer properties and then the instance name.
Check following link for solving such type of problem:
Resolving “A network-related or instance-specific error occurred while establishing a connection to SQL Server…”
Note:
You have to check for the sql server remote access settings if above connection does not work. Check the following links to make it work:
How to configure SQL Server 2005 to allow remote connections
Remote Access Settings for SQL Server
Connection string reference:
Connection strings for SQL Server 2008
Related
When I run the following line of code locally it runs succesfully. When I upload the code to the Arvixe web server I get the exception. I can read and write the temp folder as found by Path.GetTempPath()
I understand that XMLSerializer needs a temp path to create .DLLs. Does ASP.NET use a different temp path that it does not have permissions? I have compiled as Generate Serialization Assemblies Auto, Off and On to no avail. It must be a server setting as it runs on another Arvixe server but I dont know what to ask the server admins to do.
'This is the code line that causes the exception:
Sub Test
Dim formatter = New XmlSerializer(GetType(TestSMTPClass))
End Sub`
'This is a simple class we are trying to serialize
Public Class TestSMTPClass
Property ServerIP As String
Property Port As String
End Class
Throws this exception
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
ex.ToString
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.Win32.Fusion.ReadCache(ArrayList alAssems, String name, UInt32 nFlag)
at System.Reflection.RuntimeAssembly.EnumerateCache(AssemblyName partialName)
at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadWithPartialName(String partialName, Evidence securityEvidence)
at System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly(Type type, String defaultNamespace, XmlSerializerImplementation& contract)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at OCC_Competition.TestSMTP.btnTestCode_Click(Object sender, EventArgs e)
I have one asp code which is working perfectly on one system. I am using Microsoft web matrix to run it. But when I am trying to run it in another system, I am getting some errors:
Server Error in '/' Application.
Security Exception
Description: The application attempted to perform an operation not
allowed by the security policy. To grant this application the
required permission please contact your system administrator or change
the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: The source was
not found, but some or all event logs could not be searched.
Inaccessible logs: Security.
Source Error:
Line 136: catch (Exception ex1)
Line 137: {
Line 138: EventLog.WriteEntry("GLOBAL_ASAX.Session_Start", ex1.Message + ": " + ex1.StackTrace, EventLogEntryType.Error);
Line 139: }
Line 140: }
Source File: c:\Users\sysadmin\Documents\NET2_VXLICENSING_Web\Global.asax Line: 138
Stack Trace:
[SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]
System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly) +665
System.Diagnostics.EventLog.SourceExists(String source, String machineName) +104
System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName) +75
System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +205
System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +87
System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type) +14
ASP.global_asax.Session_Start(Object sender, EventArgs e) in c:\Users\sysadmin\Documents\NET2_VXLICENSING_Web\Global.asax:138
System.Web.SessionState.SessionStateModule.RaiseOnStart(EventArgs e) +8879616
System.Web.SessionState.SessionStateModule.CompleteAcquireState() +237
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +504
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +66
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
I searched a lot on the internet about it but nothing is working. I also updated registry keys.
I have a ASP.NET (VB.NET) web application (targeting .NET 4 Framework) which throws an exception intermittently when trying to invoke a web method via web reference. The web reference is the old school ASP.NET web services with the .asmx file extension.
The main web application and the web service are both on IIS 7.5 / Windows 2008 SP1. In IIS both apps are on the same website but in different application pools.
The exception states "An existing connection was forcibly closed by the remote host". This error is strange because it doesn't throw the exception the first several times when the web method is called. But when the error is thrown, it will then continue to be thrown on every following instance. Restarting the app pool in IIS fixes the error.
The data being transmitted is minimal so I don't think it is related the size of the data.
Recently we installed an F5 device that acts as a reverse proxy. The web service is now running behind this device. We did this in order to move the application to a DMZ (Demilitarized Zone). This could be the cause to this issue but if it is I am unsure how to properly configure it.
Here is my code:
_webService = New BWebService.BWebService()
_webService.Url = EnvironmentSettingsLocator.Settings.BWebServiceWsdl
If Not _webService.IsExistingUser(userId) Then
' Do Something
end if
Here is the exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Apex3Web.BIRVWebService.BIRVWebService.IsExistingUser(Int32 userCode) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Web References\BIRVWebService\Reference.vb:line 501
at Apex3Web.ManageExaminee.GridViewExaminees_RowDataBound(Object sender, GridViewRowEventArgs e) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Forms\Examiner\ManageExaminee.aspx.vb:line 651
at System.Web.UI.WebControls.GridView.OnRowDataBound(GridViewRowEventArgs e)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
at Apex3Web.ManageExaminee.FindCommand_Click(Object sender, EventArgs e) in C:\Users\Ryan.DeFour.ctr\Documents\Work\TFS Source Code 2010\APEX4CMMI\APEXDevelopment\Apex3Web\Apex3Web\Forms\Examiner\ManageExaminee.aspx.vb:line 539
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
The source of our issue was the newly installed F5 BigIP reverse proxy device which had SSL load balancing capabilities. The application threw exceptions during invocations to SOAP-based services (both WCF and ASMX). While speaking to an F5 representative, we were able to properly configure the device so requests would simply pass through the device instead of using the load balancing functions. This was probably not the most elegant solution, but in interest of time this is what we had to do to make it happen.
I have a mail send script which is used to send out confirmations to users and staff when registrations occur etc. Of recent it seems we have been experiencing issues with the mail sending get very intermittent sends, and mainly erroring.
I've been working with the hoster to no avail. The exception is as follows:
[SocketException (0x2745): An established connection was aborted by the software in your host machine]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6528783
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +130
[IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +296
System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count) +45
System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count) +106
System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +203
System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +16
System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) +54
System.Net.Mail.DataStopCommand.Send(SmtpConnection conn) +28
System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args) +8
System.Net.ClosableStream.Close() +54
System.Net.Mail.MailWriter.Close() +65
System.Net.Mail.SmtpClient.Send(MailMessage message) +1433
Now I have tried different authenticated users, different email contents and the common theme seems to be email with an attachment or emails with an HTML body seem prone to failure. My view is firmly that the mail server is the party that is disconnecting the request.
For reference I'm using asp.net 4.0 with a very standard set of code.
My hoster seems unable to locate or even resolve the issue.
I keep getting the following error when trying to run an application in the production environment with "anonymous" authentication and hardcoded username.
When I turn on basic authentication, which then prompts for username/password everything works like a charm. but I need to get the hardcoded version to work as well. Can't figure out whats going on.
Everything works perfectly on another server.
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations
error occurred.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryServicesCOMException (0x80072020): An operations error occurred.]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +781
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_SchemaEntry() +49
System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry
de) +62
System.DirectoryServices.AccountManagement.ADStoreCtx..ctor(DirectoryEntry
ctxBase, Boolean ownCtxBase, String username, String password,
ContextOptions options) +123
System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry
entry) +234
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
+497
[PrincipalOperationException: An operations error occurred.]
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
+534256
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit()
+61
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
+141
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()
+42
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext
context, Type principalType, Nullable`1 identityType, String
identityValue, DateTime refDate) +27
System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext
context, String identityValue) +95
SERT_BO.ADHelper.UserBelongsToGrp(String adGroup, String sAMAccountName, String& emailAddr, String& fullName) in
D:\SERT\BusinessObjects\SERT_BO\ADHelper.cs:199
SERT_BO.UserSession.GetUserSession(String userName) in D:\SERT\BusinessObjects\SERT_BO\UserSession.cs:44
SERT.SetUserSession.Page_Load(Object sender, EventArgs e) in D:\SERT\SERT\SERT\SetUserSession.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+3064
One thing to check is that the AppPool in which the ASP.NET app is running has the right privileges. As a quick test you can set the identity of the AppPool to Local System and see if this solves the issue. If the problem is here, then you can set the application pool identity to a (domain?) user that has enough privileges on this server.
looks like the issue was that the server was looking at the wrong AD controller. it had to be written out COMPLETELY.