plesk panel using host user in Connection String in asp.net - asp.net

I have developed a web apllication in asp.net with its connection String in web.config file and working very well in localhost. But when i deployed to hosting server using windows shared hosting it fives the error
Logic failed for user anama76
where anama76 is my domain user.My database userName is anama_Muneeb. I am finding it difficult to know that why connection string is using the domain user to connect to Db.
I have used connection in web.config to make sql server authentication
What is the solution

Your connection string must match the user name:
<add
name="ConnectionString"
connectionString="Data Source=your_database_server;Initial Catalog=your_database_name;User Id=anama_Muneeb;Password='your_password';"
providerName="System.Data.SqlClient"/>

Related

How to connect ASP.NET app to remote SQL Server

I need help connecting my Web App to a remote database (SQL Server).
I have tried many suggested solutions but I can't seem to come right.
This is how I connect to a local database, it works 100%:
<add name="DBCS" connectionString="Data Source=serverName;Initial Catalog=MVNE_Website;Integrated Security=True" providerName="System.Data.SqlClient" />
My ASP.NET Web App is hosted on one server, and the database is on a separate server.
The remote DB server is 100% configured to allow remote connections and firewall rules also adhere to the connection protocols. I think it is just my connection string that is incorrect but I don't know why??
Here it is(conn string for remote SQL server)
<add name="DBCS" connectionString="server=serverIP\serverName; database=MVNE_Website; Integrated Security=True" providerName="System.Data.SqlClient" />
I don't use a username or password when connecting to this remote SQL Server so I did not see a point in adding it in the conn string?
There can be a few reasons why this will not work. Here are 2 common ones:
Your web application will pass the username the application pool is running under, (which by default is some system user) to SQL Server. Change this to be a service account which has access to SQL Server.
If you are hopping across 2 or more servers to pass the credentials between IIS and SQL Server, you may need to implement Kerberos, which is a way to preserve the credentials. This is a complex network configuration thing.
Check point 1 first.
:/
In my web.config file custom errors mode was on RemoteOnly, so I turned it off and saw that my connection string was never the problem, the actual problem was that the app was trying to insert null into a primary key field that does not allow null, i never set the PK to auto increment
.. sorry and thanks

azure connection string format - adding in azure

I am rebuilding a web app in Azure, I used to have all my app settings and connection strings in azure. So I have put the app settings back in, but the connection string for the Azure SQL server doesn't like what I am putting in.
In the web.config I have this
<add name="LeisureInsureEntities" connectionString="metadata=res://*/LeisureModel.csdl|res://*/LeisureModel.ssdl|res://*/LeisureModel.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:leisureinsure.database.windows.net,1433;initial catalog=leisureinsure-website-preprod;persist security info=True;user id=XXXXXX;password=XXXXXX;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
But I am having issues putting this into the value input field in azure.
You probably don't need the metadata information here. When I work with EF in Azure, I just use the connection string from the portal. e. g.:
data source=tcp:leisureinsure.database.windows.net,1433;initial catalog=leisureinsure-website-preprod;persist security info=True;user id=XXXXXX;password=XXXXXX;multipleactiveresultsets=True

Correct connection string MS sql server database 2008

Was hoping for a little help with my connection string to ms sql server 2008 database.
Server Type: Database Engine
Sever name: MyServer
Authentication: Windows Authentication
User Name VAW\Username
the connection string I am using at the moment is as follow
<add name="Name" connectionString="Data Source=111.111.1.1;Initial Catalog=HRElearning;MultipleActiveResultSets=True;Trusted_Connection=true;" providerName="System.Data.EntityClient" />
Error I am getting is System.Data.SqlClient.SqlException: Login failed for user 'VAW\MAWSON$'.
I to agree using VS is the better way to go, but to understand connectionstrings in general, here is the site that explains it. Once you understand exactly what is going on, freehanding them is not difficult.
The connection string you have assumes the user you are running the app with is the user you want to connect with. If you want to run app with UserA and connect with UserB then you must specify the username and password and remove "Trusted_Connection=true".

Configure IIS 8 for SQL Server Authentication

I'm getting the following error when trying to query SQL Server 2012 from Windows 2012 IIS 8.5, in an MVC 4 website:
SqlException (0x80131904): Login failed for user [domain/user]
I have the connection string in Web.config set up just the way we did it back in the olden days:
<add name="MYPROJECT.Properties.Settings.defaultConn" connectionString="Data Source=MYSERVER;Initial Catalog=MYDATABASE;Persist Security Info=True;User ID=MYUSER;Password=MYPASSWORD"
IIS8 seems to be using an Application Pool to login, bypassing the connectionstring in Web.config.
Database and Website are on different servers. Is there a straightforward way that I can configure IIS to bypass the Application Pool and read the connectionstring from Web.config?
If Persist security info is set to true, it will be ignored. From MSDN
The ConnectionString is similar to an OLE DB connection string, but is not identical. Unlike OLE DB or ADO, the connection string that is returned is the same as the user-set ConnectionString, minus security information if the Persist Security Info value is set to false (default). The .NET Framework Data Provider for SQL Server does not persist or return the password in a connection string unless you set Persist Security Info to true.

How to connect to remotely SQL Server 2008 using MVC3 EF4

I'm trying to connect remotely and I have the following connection string on my MVC3 using EF4 ctp5 code first
<add name="ApplicationServicesX"
connectionString="provider=System.Data.SqlClient;provider connection string='Data Source=asc-svr2;
Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
and it gives an error
[ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.]
and
Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
my controller looks like this
public ActionResult Index()
{
var post = cmsDB.Posts.ToList();
return View(post);
}
When I run the code on my local machine no problem at all but when I get into
remotely connecting into SQL Server 2008 the problem arises.
Thanks a lot for any help.
Your connection string is configured to use Integrated Windows Authentication (Integrated Security=True). For this to work make sure you have enabled NTLM in IIS. Also if the SQL Server is on a different physical machine than the web server you might need to configure delegation. As an alternative you could use SQL authentication with a fixed account:
<add name="ApplicationServicesX"
connectionString="provider=System.Data.SqlClient;provider connection string='Data Source=asc-svr2; Initial Catalog=AdventureWorks;User Id=foo;Password=secret;Connection Timeout=60;multipleactiveresultsets=true'"
providerName="System.Data.EntityClient" />

Resources