When I publish my project I get this error:
System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'serverusername'. at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString
The reason why Im getting the error is cause I'm using windowns authentication for that connectionString. It works well in my local machine but when I publish different server that has that site it gives me that error. It should be using windowns authentication because this is not the first app I have publish on that server, so I dont understand why when it connects to that server 'thisserver' it doesn't connect with the correct windowns authentication.
<add name="wfserver"
connectionString="Server=thisserver;Database=thisdatabase;Integrated Security=True;MultipleActiveResultSets=True;Trusted_Connection=True;"
providerName="System.Data.SqlClient" />
// using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["wfserver"].ToString()))
{
"select * from mytable where year = @yearnumber ";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
sda.SelectCommand.Parameters.AddWithValue("@yearnumber", year);
DataTable dt = new DataTable();
sda.Fill(dt);
List<workflowMonthly> modelList = new List<workflowMonthly>();
foreach (DataRow row in dt.Rows)
{
var model = new workflowMonthly()
{
WorkflowName = row["WorkflowName"].ToString(),
...
};
modelList.Add(model);
}
return modelList;
}
I have a form and the issue happens after I click submit and looks for the data
View:
@User.Identity.Name (shows correct windows authentication)
@using (Html.BeginForm("page", "Reports", FormMethod.Post, new { id = "commentForm", role = "form" }))
{}
Are you publishing the site local? If so then what ever you are using to access SQL Server from SSMS you should not be have a problem. If you are publishing to another location then I would create a dbname and password and replace you Webconfig CnnectionString.
In shorts create a sa like account and password. Try something like this. "Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;"
User contributions licensed under CC BY-SA 3.0