Server Error in '/' Application - asp.net

After searching my question's answer from stack overflow and other forums i am going to ask it myself, may be some one can guide me and make my way easy with asp.net programming.
I have a issue with saving values from my live website to database but all time i got error.
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".
i have tried to view it by putting mode=off in my web.config but i am unable to view details of my error.
here is my web.config
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
<authentication mode="None"/>
</system.web>
<location allowOverride="true">
<appSettings>
<add key="#" value="Password=#;Persist Security Info=True;User ID=#;Initial Catalog=#;Data Source=#"/>
</appSettings>
</location>
</configuration>
I have tested my database and my connection string on my live database using local solution of my project but when ever i tried to test it using my live server which is arvixe i am unable.
My fellow suggest me to use
<connectionStrings>
<add name="#" connectionString="Data Source=#;Initial Catalog=#;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
but it is not working with live server.
I am using app settings for connection string and i am confident with it because it is working fine with my local and live database.
I request to developers to test my online quran reading page and try to figure it out.

If you're using Sql Express, try this connection string
Data Source=.\SQLEXPRESS;DataBase=DBName;User ID=abcd;Password=xxxx;
As far as I know Integrated Security=True works with windows authentication. If you want to use this option then change the <authentication mode="None"/> to <authentication mode="Windows"/>.
If you are using Sql Server, may be try the following connection string
Standard Connection string
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
Trusted Connection
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

Related

How should be connection string for connection with SQL Server in asp.net

I have developed a website in asp.net and upload onto a server. But I unable to connect to my SQL Server database (on localhost, I am able to run but not on the server)
I am using following code.
con = new SqlConnection("server=**********,****\\sqlexpress;Database=******;User ID=******;Password=*********");
con.Open();
but I'm unable to open the connection.
I am getting this error related to web.config:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the defaultRedirect attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
So please help me how can resolve it
Use the following Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;
Check the instance name of the remote server. Check if you can connect in sql management studio and use the same credentials in your app.
I've answered two similar questions on SO, first try creating a .UDL file and test your connection from there. You can then copy and paste the connection string. You may need to remove the Provider property though.
See this question and this one for a full description.

ASP.NET MVC 4 application database connection issue after session timeout

I have an MVC 4 website using .NET framework 4.5 that works fine at first. It allows me to login and go about my business adding, deleteing and editing records. As such, it is obviously initially connecting to the database without a probelm. However, if I leave it inactive for a while and come back at a later time, and then click a link to a page that shows data from my database, I get the following error:
The SSE Provider did not find the database file specified in the connection string. At the configured trust level (below High trust level), the SSE provider cannot automatically create the database file.
The website works fine on my localhost, but not when I host it online. I use shared hosting for this. I've done extensive searching online and found lots of people getting the same error, but they don't seem to have a website that works initially and then suddenly stops working. The solutions I've found online say something along the lines of:
add these two lines to your web.config file
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=p3swhsql-v15.shr.phx3.secureserver.net; Initial Catalog=DatabaseName; User ID=****; Password='****';"/>
by default the .net site is trying to find your database in the local filesystem in this case would be the app_data subfolder under the wwwroot directory. simply removing the connectionstring and replacing it with the database connection solves the issue. My example utilizes an SQL db on godaddy's server. however i'm sure you can replace the connection string with the appropriate string for your connection. good luck and i hope this helps anyone that may be having this issue
What my program seems to be doing is using the online database when I first login, and then reverting to trying to use the database in the local filesystem once the session timesout. This is very frustrating. My web.config file looks as follows:
<connectionStrings>
<remove name="DefaultConnection"/>
<add name="DefaultConnection" connectionString="Data Source=winsqls01.cpt.wa.co.za;Initial Catalog=SportFantasySA;Persist Security Info=True;User ID=*****;Password=*****" providerName="System.Data.SqlClient"/>
</connectionStrings>
Please help. I'm desperate to get this working. I understand that it can't create the sql express database in the hosting space, that's why I'm using the connection string for the database on my hosting company's server.
If you have hosted it on Godaddy go for the connection string as
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" connectionStringName="LocalSqlServer"
..other attributes here... /></providers>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=xxxx; Initial Catalog=xxx; User ID=xxx; Password=xxx;"
providerName="System.Data.SqlClient" />

Not able to uploade website on server

I am try to uploading website.I don't know how configure database(web.config file) on uploading time.I am using Somee.com , anyone familiar with somee.com Or know how to configure database the please help me.
webconfig file code
<configuration>
<connectionStrings>
<add name="abc" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Jai-Ganesh\Documents\Visual Studio 2010\WebSites\testinmg\App_Data\Database.mdf;Integrated Security=True;User Instance=True"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="RemoteOnly" ></customErrors>
</system.web>
</configuration>
Note: I don't know what is path of the dataSource in server.
Link of the page:
[http://www.imureditor.somee.com/add_value.aspx][1]
first you need to contact your hosting provider for connection string. They will give you the ip address (you can also the host name) which you can then configure it.
See the exmaple below;
<add name="connectStringName" connectionString="Data Source=somee.com;User ID=yourusernameforDB;password=yourpasswordforDB;Initial Catalog=yourDBName;" />
OR take a real example below;
<add name="KenSchoolConnectionString" connectionString="Password=1234;Data Source=192.168.1.1;Integrated Security=False;Initial Catalog=KenMISSchoolDB;User ID=sa" />
OR
Go to connectionstrings.com
Your connection string references your local SQL Server instance and tries to attach a local file; this connection string will need to be changed to reflect the setup on the server, so you'll need to specify the Data Source, Catalog, User ID and Password - Integrated Security won't work, and attaching *.mdf files from App_Data probably won't either.
Your service provider is responsible for giving you the credentials needed for this, we can't guess them.

web.config and membership

I have an Runtime error when I'm trying to perform login action or create user action on published website.
I have an ASPNETDB.MDF in appData folder, that created from ASP.NET Configuration.
I created new database in hosting, exported from ASPNETDB.MDF to a new database. I changed connection string.
Localy it work perfect, even with new connection string, but after i publish it i have an Runtime error.
I'm using asp login control and CreateUserWizard.
BTW, i've created some GridView and SqlDataSource to show all users, and it works.. But login and createWizard are not.
web.config
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Server=mssql3322.dotnet-host.com;Database=aspnetdb3;Uid=SomeUserNAme;Password=SomePassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
BTW, i tryed to add membership provider to web.config and it didn't work even localy ))
UPD:
The error
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)
Well for starters you could add the following to your web.config:
<configuration>
<system.web>
<customErrors mode="off"></customErrors>
</system.web>
</configuration>
This should allow you to get a more detailed error message about what is wrong. See if that get's you started down the right path. It should at least provide more information about what might be wrong.
Update - try this in your web.config:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Server=mssql3322.dotnet-host.com;Database=aspnetdb3;Uid=SomeUserNAme;Password=SomePassword;" providerName="System.Data.SqlClient"/>
<add name="ConnectionString" connectionString="Server=mssql3322.dotnet-host.com;Database=aspnetdb3;Uid=SomeUserNAme;Password=SomePassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Update - That worked! Here is a short explanation why:
By default the ASP membership classes use the connection string LocalSqlServer. The reason the code worked on your local machine is because the connection LocalSqlServer is defined in a machine level config file to point to the local sql database. When you published it the SqlDataSource/GridView worked because it was pulling the connection named ConnectionString that pointed to the correct server. However ASP membership was still trying to connect to the LocalSqlServer connection. The above config just ignores the machine level LocalSqlServer connection and defines it's own (and it leaves the ConnectionString one in place so that the GridView continues to function).

ASP.Net (IIS 7.5) Querying Active Directory without User Credentials

I have multiple web applications that I've built for our intranet. I wanted to allow users to not worry about logging in, so these apps pull the currently logged on user when they hit the site. I used this code for this to happen:
Dim userName As String = User.Identity.Name
CurrentUser = userName.Substring(userName.IndexOf("\") + 1)
This works like a charm, no issues here. The next step is to query Active Directory for that logged in user to pull various information. How I currently have it coded, it works like a charm on the devleopment side (typical because I'm not running IIS).
The problem becomes when I publish it to my IIS server (Windows Server 2008 R2 running IIS 7.5), I get error messages that point to the specific line in my code that queries Active Directory. The interesting part is these apps were working great last week. They broke after my server admin did the latest batch of Windows Updates (please note, I am running them using .Net Framework 4.0)
Before I had each app setup so that Windows Authentication was Enabled, the other Authentication types were disabled. For providers, Negotiate is #1, NTLM is #2. For Advanced Settings, Extended Protection = Off, and Enable Kernel-mode authentication is checked.
My web.config has the following set:
<customErrors mode="Off"/>
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
These were the settings I had, and everything worked like a charm. Now to get it to somewhat work I need to swap the providers around so NTLM is #1 and Negotiate is #2. Because of this, the user's credentials are not properly passed in and the AD query fails. This is the coding I'm using for the query:
Dim adSearchRoot As New DirectoryEntry("LDAP://DC=[DOMAIN],DC=com")
Dim adSearch As New DirectorySearcher(adSearchRoot)
adSearch.Filter = "(&(ObjectClass=User)(sAMAccountName=" & CurrentUser & "))"
Dim searchResult As SearchResult = adSearch.FindOne()
Ever since the updates, when loading the site with Negotiate in front, it fails on that bottom line because I don't have a username/password set for the DirectoryEntry. Even when I set a username/password, it still does not 100% work like it used to.
So my question becomes, what do I need to do so that the user accesses the site, I can know their username, and can query active directory without requiring the use of a username/password in the DirectoryEntry??
Is it a setting in IIS?
Or do I need to recode?
web.config setting perhaps?
Do I need to revert server updates and figure out which one causes the break to occur?
Thanks for the advice in advance. If you have any questions to help answer the question, let me know.
UPDATE
I tried as Matt suggested by adding the following clip to my web.config file:
<security>
<authorization>
<add accessType="Deny" users="?" />
</authorization>
</security>
This did not work. I did some reading, and then altered this section further:
<location path="Default Web Site/NameOfApp">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false"/>
<windowsAuthentication enabled="true">
<providers>
<add value="Negotiate" />
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
<authorization>
<add accessType="Deny" users="?" />
</authorization>
</security>
</system.webServer>
</location>
In doing this I also removed the string that was higher up in my web.config section. This did not work either (fyi, this was a great reference http://www.iis.net/ConfigReference/system.webServer/security/authentication)
I then tripped across this article: http://social.technet.microsoft.com/Forums/en/winserverDS/thread/7deba16b-295a-4887-98f9-9f291ed49871 which seemed to be a similar situation. This article eventually referenced "Double Hops", after looking into this and trying a few things, this didn't solve my issue either.
Next Step
I am going to try a new IIS 7.5 implementation on a different Server 2008 R2 system and essentially start from scratch, to see if the problem recreates or not.
ANY new suggestions would be of great help.
I was able to make the code execute without any problems on a Windows 2008 Server. I created a new .NET 4.0 application pool and assigned it to the web application. I changed the web.config to deny anonymous access and use Windows authentication. The code executed without exception.
Looking at your web.config clip, I wonder if this might be what you're missing:
<system.webServer>
<security>
<authorization>
<add accessType="Deny" users="?" />
</authorization>
</security>
</system.webServer>
It's important that you have this authorization section within the system.webServer section. IIS 7 uses the system.webServer section to store some settings that were part of the metabase in IIS 6.
I had this same problem. Here's how I solved it:
Use overload 4 of 5 for the DirectoryEntry constructor which allows for not only a path, but a username, and a password as well. So, your AD connection should look like this:
DirectoryEntry adSearchRoot = new DirectoryEntry("LDAP://DC=[DOMAIN],DC=com", "DOMAIN\Username", "Password");
DirectorySearcher adSearch = new DirectorySearcher(entry);
Now, instead of "DOMAIN\Username", use a service account and then for the password, obviously, use the password for the service account.
I think as long as the service account is a member of the "Domain Users" group, then you should be able to query AD no problem.

Resources