Invalid character in a Base-64 string for connection string - asp.net

I have a Sql Server 2008 R2 connection string that looks like
<add name="DBConnectionString"
providerName="System.Data.SqlClient"
connectionString="Data Source=AYZ;Initial Catalog=AYZ;User ID=AYZ;Password=AYZ;"/>
When trying to create a new instance of SQLDatabase using EnterpriseLibrary.Data I get the above error.
connString =ConnectionStrings.ConnectionStrings["DBConnectionString"];
Database objDB = new SqlDatabase(connString);
connString has the following
Data Source=AYZ;Initial Catalog=AYZ;User ID=AYZ;Password=AYZ;
The detailed exception is as follows :
System.FormatException was unhandled by user code
Message=Invalid character in a Base-64 string.
Source=mscorlib
StackTrace:
at System.Convert.FromBase64String(String s)
at Microsoft.Practices.EnterpriseLibrary.Data.Database.DecryptConnectionString(String strEncyptConStr)
at Microsoft.Practices.EnterpriseLibrary.Data.Database..ctor(String connectionString, DbProviderFactory dbProviderFactory)
at Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase..ctor(String connectionString)
at ABC.GRC.DAL.CommonDAL..ctor() in D:\ABC\Projects\Right Price\ABC.GRC\ABC.GRC\ABC.GRC.DAL\CommonDAL.cs:line 31
at ABC.GRC.BLL.CommonBLL..ctor() in D:\ABC\Projects\Right Price\Syntel.GRC\Syntel.GRC\Syntel.GRC.BLL\CommonBLL.cs:line 14
at Global.Application_Error(Object sender, EventArgs e) in d:\ABC\Projects\Right Price\ABC.GRC\ABC.GRC\ABC.GRC.WEB\App_Code\Global.asax.cs:line 60
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.HttpApplication.RaiseOnError()
InnerException:

I think there is the problem
connString =ConnectionStrings.ConnectionStrings["ConnectionString"];
It should be
connString =ConnectionStrings.ConnectionStrings["DBConnectionString"];
Since you have key DBConnectionString in you configuration file not ConnectionString.
Useful link:
Read connection string from web.config

Related

Security Exception When i am trying to run working asp code on one system from another system

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.

The server response was: 5.7.7 Sender Unknown in Local Domain

When i tried to send a mail through SMTP server An Exception is coming.
Here is the Exception:
System.Net.Mail.SmtpException: Transaction failed.
The server response was: 5.7.7 Sender Unknown in Local Domain . at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at
System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String
deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage
message) at _Default.Button1_Click1(Object sender, EventArgs e)
in d:\pjt\mail_check\Default.aspx.cs:line 39
Check this link.It may be helpful

an unhandled exception occured while tried to send a mail in asp.net

when i tried to send a mail i got these exceptions
System.Net.Mail.SmtpException: Transaction failed. The server response
was: 5.7.7 Sender Unknown in Local Domain . at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,
String response) at System.Net.Mail.MailCommand.Send(SmtpConnection
conn, Byte[] command, String from) at
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify,
SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message) at
_Default.Button1_Click1(Object sender, EventArgs e) in d:\pjt\mail_check\Default.aspx.cs:line 39

Issue with webservice accessing database

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

Facebook SDK 5+ authentication token error: A connection attempt failed because the connected party did not properly respond after a period of time

I have an issue I have been trying to fix since this morning (now over 8h). I got the facebook cookie contents, found the auth token which works fine on its own in the browser
https://graph.facebook.com/me?access_token=201856003211297|2.AQAHJg3GugHIHhec.3600.1314442800.1-100002411647354|RAylZSUax4pdKcIt--QruS-Qcgc
But
Whenever I try to get the user information, the web-page crashes down very nicely with the error below.
I have tried to read from the page using web request:
'Dim inputFile As String = "https://graph.facebook.com/me?access_token=" & access_token
'Dim sDiskFile As String = "auth.txt"
'Dim _wrequest As WebRequest = WebRequest.Create(inputFile)
'Dim _wresponse As WebResponse
'_wresponse = _wrequest.GetResponse()
'Dim _stream As Stream = _wresponse.GetResponseStream()
'Dim oReader As New StreamReader(_stream, Encoding.ASCII)
And it crashed with the same error. I decided to give the Facebook SDK 5 a go and the same error is happening:
Dim access_token As String = GetFacebookTokenFromCookie()
If access_token = "" Then
litUser.Text = "<fb:login-button perms='email'>Login with Facebook</fb:login-button>"
Else
Dim app As New DefaultFBApp
Dim _ctx As New FacebookWebContext(app)
Dim fb As New Facebook.FacebookClient(app)
fb.AccessToken = access_token
Dim parameters As New Dictionary(Of String, Object)()
parameters("fields") = "id,name"
Dim result As Object = fb.Get(parameters)
Dim id = result.id
Dim name = result.name
Dim firstName As String = result.first_name
Dim lastName = result.last_name
Dim link = result.link
Dim username = result.username
Dim gender = result.gender
Dim male = result.locale
litUser.Text = "Welcome " & firstName
End If
DefaultFBApp is:
Public Class DefaultFBApp
Implements Facebook.IFacebookApplication
With all the must-implement fields added in and the api key and secret filled in.
Same error:
Server Error in '/' Application.
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 69.171.224.21:443
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 69.171.224.21:443
Source Error:
Line 25: parameters("fields") = "id,name"
Line 26:
Line 27: Dim result As Object = fb.Get(parameters)
Line 28:
Line 29: Dim id = result.id
Source File: masterpage.master Line: 27
Stack Trace:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 69.171.224.21:443]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +224
[WebExceptionWrapper: Unable to connect to the remote server]
FluentHttp.HttpHelper.OpenRead() +191
Facebook.FacebookClient.Api(String path, IDictionary`2 parameters, HttpMethod httpMethod, Type resultType) +253
Facebook.FacebookClient.Get(IDictionary`2 parameters) +44
ASP.masterpage_master.Page_Load(Object sender, EventArgs e) in E:\kunden\homepages\6\d364763622\www\wsb6301158401\masterpage.master:27
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Version Information: Microsoft .NET Framework Version:2.0.50727.5446; ASP.NET Version:2.0.50727.5420
Any help would be mostly appreciated

Resources