I'm creating an ASP.NET application for my company.
In Visual Studio, I used EntityFramework to connect to my SQL Server database with an edmx file. The application is using Windows authentication to connect to both the website and SQL Server.
When I run the application locally, all is working great. The Windows authentication works so my app know who I am, then it connects to SQL Server correctly and shows up data.
But when I try to deploy it on my IIS Server, I get the following error :
Login failed for user 'DOMAIN\SERVERNAME$'.
The Windows authentication works great to identify who I am in the app, but the integrated security used to connect to SQL Server is using the server identity instead of the identity of the application's user.
What you may want to know :
All users have an SQL Server account to connect through integrated security
The server is on the same Domain than our computers
The SQL Server is on another server than the machine where IIS is running, but the remote connection is activated and working
I'm using Google Chrome to test my app locally and remotely
There is the connection string I am using :
<connectionStrings>
<add name="DatabaseEntities" connectionString="metadata=res://*/Models.DatabaseModel.csdl|res://*/Models.DatabaseModel.ssdl|res://*/Models.DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string="data source=SQLSERVERNAME\INSTANCE;initial catalog=Database;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
Is it possible to use the same Windows authentication for both ASP.NET application and SQL Server ?
You should add your domain user to SQL-server logins - look here
Or remove integrated security option from connection string and add user id and password of sql server user:
<add name="DbConnectionString" connectionString="Data Source=SERVER;Initial Catalog=db;User Id=sqlusername;Password=sqluserpass;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient"/>
note that exampled connection string does not contains metadata for model-first approach
I was looking on how to set this up for SQL FILESTREAM in my API.
Update the Host File with the IPV4 for the FQDN or SERVERNAME of the SQL Server.
In Credential Manager add 2 Credentials.
One for File Share the other Port 1433.
The File Transfer does not require the Domain, but the Port 1433 version does.
After this was able to use Trusted Connection or Integrated Security=SSPI to access the FILESTREAM.
Related
I create a website with a SQL Server database and put it on a host ...
I just want to know if there is a way that when I open my website on a special PC, I could connect to the PC's SQL Server database for reading and writing ...
Let me know if there is a special connection string for that !
You need to use server IP address and user id , password for connect to database.
Like
<add name="DefaultConnection" connectionString="Data Source=198.0.0.1;Initial Catalog=Database;user id=user1;password=[system];" providerName="System.Data.SqlClient" />
IP - 198.0.0.1
User id - user1
password - [system]
Note -
When you accessing your database from other computer , windows
authentication will not work.
Set sql server authentication in sql server
Allow remote connections to sql server
Allow Sql server port into firewall
Then try.
I have developed a web site that utilizes login in control using the ASP.NET Web Site Administration Tool. I then moved the entire project over to the server that will be hosting the project. I have the site on IIS 7 but when I try to login, I get the error message:
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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)
I have given the proper permissions to NETWORKSERVICE. It seems from browsing around online that this is a sql server problem. It works fine in VWD Express but not on IIS. I know that the roles,users,permissions are stored in a .mdf but I'm guessing that it's not being accessed correctly.
Does anyone have any insight on this?
Here is my connection string:
add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-GMPL-20130618083445;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-GMPL-20130618083445.mdf"
providerName="System.Data.SqlClient"
Thank you in advance!
It's trying to use "LocalDB", which is probably not installed on your server. You probably should be connecting to a regular database, as opposed to LocalDB.
LocalDB is a new kind of SQL Express - seems to be made for development machines rather than for actual servers.
change Connection string to
"Data Source=.\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True"
I am trying to connect to a SQL Server database that is behind a firewall. The asp.net application which is in the DMZ tries to connect to the database, however I am getting an error (The webapp works fine from my local machine):
When I telnet:
open 0.0.0.0 1433
it says:
Connecting to 0.0.0.0 ...
Connection to host lost
Does this mean that the firewall is blocking the incoming request? Or is this something else? (IT support assured me the port is open)
Connection string:
data source=0.0.0.0; initial catalog=mydb;user id=xxxx;password=xxxx;persist security info=True;packet size=4096;
Create a new UDL file on your ASP server. Open the UDL file, use the interface to successfully connect to the SQL server and save the file. Open the UDL file in a text editor and copy the connection string into your application.
If your sql server is behind a firewall (and it's a good thing that it is), then your web app should not be connecting to it directly. Rather, it should be going through some sort of service layer. That can be implemented in a variety of ways with different technologies. This service should be located physically on a machine that can access the db, and the web server should not be allowed to directly connect to the db machine (or cluster).
So, with that said, let's address your connection string. Try adding 'integrated security=true'. Here's an example:
<connectionStrings>
<add name="ConnStringDb1" connectionString="Data Source=MY_SERVER_NAME_OR_IP;Initial Catalog=MyDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Again, it's important to note that the web app itself should only be calling to this service layer (perhaps WCF, or possibly a COM component), not connecting to the data access layer directly. There are lots of samples on how to design these types of applications. Here's one that hopefully may help. http://www.c-sharpcorner.com/UploadFile/SukeshMarla/3-tier-architecture-using-Asp-Net/. Good luck.
My Asp.Net/C# web app hosted on IIS is using 2 different service accounts to access 2 DBs on 2 SQL servers on the network. IIS is running as service account1 coonnecting to DB1 on SQL server1.
I have the User ID, Password for account 2 configured in the web.config connectionstring expecting this to supersede the IIS setting just for DB2 on SQL server2. This is not working. Is there a better way to handle this? Appreciate your help.
Obviously, DB1 uses Windows Authentication and should be configured for that. Make sure, the connection string is configured to select "Integrated Security=true;" in its connection string. DB2 needs SQLServerAuthentication enabled. No impersonation will work for DB2 but a regular connection string will do:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
See also: http://www.connectionstrings.com/sql-server-2008
I am using Amazon EC2 server, with Windows Server. It has installed SQL Server 2008 R2 Express and IIS7. I have made a web site, and want to test this web app. But it is not connecting to the SQL Server. I have tried different connection strings. But it is giving this error:
Server Error in '/' Application.
Cannot open database "Avon" requested
by the login. The login failed. Login
failed for user 'NT AUTHORITY\NETWORK
SERVICE'.
I have tried to change it from windows authentication to SQL Server authentication and vice versa. But same error.
My connection string is
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Avon.mdf;Integrated Security=True;User Instance=true;"
I have copied Avon.mdf and Avon.ldf file into App_data. I want it to connect either by local server, or by IP address.
I appreciate your answers.
Thanks
If the identity under which the application is running does not have access to the database, you will need to provide user name and password in the connection string.
Example:
Password=somepassword;Persist Security Info=True;User ID=someuserid;Initial Catalog=DatabaseName;Data Source=.\SQLEXPRESS
You could also try changing your Application pool identiy to a user that has access to the database. or set up asp.net impersonation
Application pool on II7 work in context of user NETWORK SERVICE. In your connection string you have Integrated Security=True.
Solutions:
1) Change connection string to use userId+password
2) Change application pool user - not recommended if you don't understand how it works
3) Allow user NETWORK SERVICE connect to your sql server\data base - not recommended because many others services use this technical account.