Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication. in Entity Framework - entity-framework

getting {"Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication."} please give any suggetion why this error is throwing.
public int Find(string AccountNumber, DateTime DepositedDT)
{
IsPigmySync pigmySync = new IsPigmySync();
pigmySync.AccountNumber = AccountNumber;
pigmySync.DepositedDT = DepositedDT;
SqlParameter issynced = new SqlParameter("#p2", System.Data.SqlDbType.Int);
issynced.Direction = ParameterDirection.Output;
try
{
var sql = "exec Pigmy_GetPigmyItems #p0,#p1,#p2 OUT";
// var result = _context.Database.ExecuteSqlInterpolated(sqlQuery);
var result = _context.Database.ExecuteSqlCommand(sql, pigmySync.AccountNumber, pigmySync.DepositedDT, issynced);
int ab = result;
pigmySync.IsSynced = (int)issynced.Value;
return pigmySync.IsSynced;
}
catch (Exception ex)
{
return 0;
}
above is my code snippet. using entity framework,xamarin forms

Related

Login error when input wrong credentials " An unhandled exception occurred during the execution of the current web request

These in ASP.NET application of which I am starting to learn. There is an error stating System.IndexOutOfRangeException: UserId.
Here is the code:
protected void ValidateUser(object sender, EventArgs e)
{
int userId = 0;
string roles = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Validate_User"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#Username", Login1.UserName);
cmd.Parameters.AddWithValue("#Password", Login1.Password);
cmd.Connection = con;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
userId = Convert.ToInt32(reader["UserId"]);
roles = reader["Roles"].ToString();
con.Close();
}
switch (userId)
{
case -1:
Login1.FailureText = "Username and/or password is incorrect.";
break;
case -2:
Login1.FailureText = "Account has not been activated.";
break;
default:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Login1.UserName, DateTime.Now, DateTime.Now.AddMinutes(2880), Login1.RememberMeSet, roles, FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(Login1.UserName, Login1.RememberMeSet));
break;
}
}
}
}
}
Here is the Image to the error
Error message

RuntimeBinderException: Convert type System.Threading.Tasks.Task<object> to string

I do an example with signalR. But it doesn't function because of one mistake.
The one mistake (can not convert type system.threading.tasks.task< object> to string) is in this line:
return context.Clients.All.RecieveNotification(simple);
It is at the bottom of the code you can see below.
Below you see the method I wrote. There I do a connection with the database and get the content with a command/query.
Then a few checks and also SqlDependency.
public string SendNotifications()
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
{
string query = "SELECT eintrag FROM [dbo].[simple_column]";
connection.Open();
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Notification = null;
DataTable dt = new DataTable();
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
var reader = command.ExecuteReader();
dt.Load(reader);
if (dt.Rows.Count > 0)
{
simple = dt.Rows[0]["eintrag"].ToString();
}
}
}
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
return context.Clients.All.RecieveNotification(simple);
}
And here I use the function:
var notifications = $.connection.notificationHub;
notifications.client.recieveNotification = function (simple) {
// Add the message to the page.
$('#dbMessage').text(simple);
};
I hope you can help me.
Thanks.

Submitting a WebRequest from within a CLR Trigger

I just implemented a prototype solution for updating my caching server in real-time by assigning a CLR Trigger to a table so that whenever a certain column is updated the URL called from the trigger will update the caching server with the correct data.
It's working fine and the code is as follows:
[Microsoft.SqlServer.Server.SqlTrigger(Name = "AdStatusChanged", Target = "Ads", Event = "FOR UPDATE")]
public static void AdStatusChanged()
{
SqlTriggerContext triggContext = SqlContext.TriggerContext;
int adID = 0, adStatusID_Old = 0, adStatusID_New = 0;
if (triggContext.TriggerAction == TriggerAction.Update)
{
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
conn.Open();
SqlCommand sqlComm = new SqlCommand();
SqlPipe sqlP = SqlContext.Pipe;
sqlComm.Connection = conn;
sqlComm.CommandText = "SELECT AdID, AdStatusID from INSERTED";
SqlDataReader reader = sqlComm.ExecuteReader();
if (reader.Read())
{
adID = reader.GetInt32(0);
adStatusID_New = reader.GetInt32(1);
}
reader.Close();
sqlComm.CommandText = "SELECT AdID, AdStatusID from DELETED WHERE AdID = " + adID;
reader = sqlComm.ExecuteReader();
if (reader.Read())
{
adID = reader.GetInt32(0);
adStatusID_Old = reader.GetInt32(1);
}
}
if (adID == 0 || adStatusID_New == adStatusID_Old)
{
// Check could be more thorough !
return;
}
WebResponse httpResponse = null;
try
{
string apiURL = string.Format("{0}/{1}", "http://localhost:14003/Home", "UpdateAdStatus?adID=" + adID + "&adStatusID=" + adStatusID_New);
var httpWebRequest = (HttpWebRequest)WebRequest.Create(apiURL);
httpWebRequest.Method = "GET";
httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
// check for successful response
}
catch (Exception ex)
{
Log("WebRequest from within SQL Server failed ! " + ex.Message);
}
finally
{
if (httpResponse != null)
{
httpResponse.Close();
}
}
}
}
I would like to have some expert/experienced views on the "CONS" of this approach regarding performance, deadlocks, sql crashing, or other areas that could be of potential concern.
Has anyone tried this (I'm sure many must have) and what was the result ? a successful implementation or did you revert to some other method or updating the cache real-time?

Crystal report -- invalid log on parameter error

I have a crystal report which was working fine on my local machine but when I moved it to my server it's giving me a "Incorrect Log on parameters".
Code is below. It's called from a .net application
Dim CR As New ReportDocument
Dim str As String = Application.StartupPath
If PrintDialog1.ShowDialog() <> Windows.Forms.DialogResult.OK Then Exit Sub
CR.Load(Application.StartupPath & "\CR Reports\BookPickByConsignee.rpt")
CR.SetParameterValue("param_picknumber", Me.txtpickNumber.Text.Trim())
CR.DataSourceConnections.Item(0).SetConnection(Configuration.ConfigurationSettings.AppSettings("DatabaseServer").ToString(), Configuration.ConfigurationSettings.AppSettings("DatabaseName").ToString(), Configuration.ConfigurationSettings.AppSettings("UserName").ToString(), Configuration.ConfigurationSettings.AppSettings("Password").ToString())
'CR.DataSourceConnections.Item(0).SetLogon("sa", "pwd")
' CR.SetDatabaseLogon("sa", "pwd")
CR.PrintOptions.PrinterName = PrintDialog1.PrinterSettings.PrinterName
CR.PrintToPrinter(Me.txtCopies.Text, True, 1, 100)
CR.Close()
You can use the following code to apply certain connection details for a report at run time.
Sorry, code in c#.
Please use that method just after loading report rpt file, instead of CR.DataSourceConnections.Item(0).SetConnection and pass required connection details to method, it will work.
public static void CrystalReportLogOn(ReportDocument reportParameters,
string serverName,
string databaseName,
string userName,
string password)
{
TableLogOnInfo logOnInfo;
ReportDocument subRd;
Sections sects;
ReportObjects ros;
SubreportObject sro;
if (reportParameters == null)
{
throw new ArgumentNullException("reportParameters");
}
try
{
foreach (CrystalDecisions.CrystalReports.Engine.Table t in reportParameters.Database.Tables)
{
logOnInfo = t.LogOnInfo;
logOnInfo.ReportName = reportParameters.Name;
logOnInfo.ConnectionInfo.ServerName = serverName;
logOnInfo.ConnectionInfo.DatabaseName = databaseName;
logOnInfo.ConnectionInfo.UserID = userName;
logOnInfo.ConnectionInfo.Password = password;
logOnInfo.TableName = t.Name;
t.ApplyLogOnInfo(logOnInfo);
t.Location = t.Name;
}
}
catch
{
throw;
}
sects = reportParameters.ReportDefinition.Sections;
foreach (Section sect in sects)
{
ros = sect.ReportObjects;
foreach (ReportObject ro in ros)
{
if (ro.Kind == ReportObjectKind.SubreportObject)
{
sro = (SubreportObject)ro;
subRd = sro.OpenSubreport(sro.SubreportName);
try
{
foreach (CrystalDecisions.CrystalReports.Engine.Table t in subRd.Database.Tables)
{
logOnInfo = t.LogOnInfo;
logOnInfo.ReportName = reportParameters.Name;
logOnInfo.ConnectionInfo.ServerName = serverName;
logOnInfo.ConnectionInfo.DatabaseName = databaseName;
logOnInfo.ConnectionInfo.UserID = userName;
logOnInfo.ConnectionInfo.Password = password;
logOnInfo.TableName = t.Name;
t.ApplyLogOnInfo(logOnInfo);
}
}
catch
{
throw;
}
}
}
}
}

Dynamic CRM 4.0 SOAP exception

When I try to develop CRM stuff, using the code below:
public static CrmService GetCrmService()
{
//Standard CRM setup
var authenticationToken = new CrmAuthenticationToken();
//Using the active directory
authenticationToken.AuthenticationType = 0;
authenticationToken.OrganizationName = "myorganizationName";
var crmService = new CrmService();
crmService.PreAuthenticate = true;
crmService.UseDefaultCredentials = false;
crmService.CrmAuthenticationTokenValue = authenticationToken;
crmService.Credentials = new NetworkCredential("username", "password", "domain");
crmService.Url = "http://<ourserver>/mscrmservices/2007/CrmServiceWsdl.aspx";
return crmService;
}
public void RetrieveAccount()
{
var accountGuid = new Guid("088FFC38-8285-4AF5-8E36-84BAD6B268ED");
var crmService = GetCrmService();
//Set the column to return
var returnedColumns = new ColumnSet();
returnedColumns.Attributes = new string[] { "name", "telephone1", "customertypecode" };
try
{
var receivedAccount = crmService.Retrieve(EntityName.account.ToString(), accountGuid, returnedColumns) as account;
if (receivedAccount != null)
{
Debug.WriteLine(string.Format("Name: {0}, Telephone: {1}", receivedAccount.name, receivedAccount.telephone1));
}
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
It comes up with the following exception:
"Possible SOAP version mismatch:
Envelope namespace
http://schemas.xmlsoap.org/wsdl/ was
unexpected. Expecting
http://schemas.xmlsoap.org/soap/envelope/."
Is there any solution for this problem ?
Thanks in advance.
After spending several hours, I have figured out that the problem was occured because of using the wrong service address. Instead of connecting to the actual address, I have connected to a redirected address.
So in the above code, I used the redirected address:
https://servername/MSCrmServices/2007/CrmServiceWsdl.aspx
I should have been used the following address:
https://servername/mscrmservices/2007/crmservice.asmx
Cheers.