Create a connection string / connect to a database in asp.net? - c#

I am trying to publish a website to make it go live and need to connect to a database. Currently I am using:
<connectionStrings>
<add name="UniversityContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=RoomAudit;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\RoomAuditSystem.mdf" providerName="System.Data.SqlClient" />-->
</connectionStrings>
in my web.config which obviously using my local machine.
I've looked online and on here and can't seem to find a clear cut tutorial. Here is the database details:
DATABASE SERVER
mysql4.gear.host
with my username and password with reading and writing permissions.
If someone could point me in the right direction I would appreciate it - I'm also using Entity Framework if that makes any difference?
EDIT:
This is my new connection string:
<add name="UniversityContext" connectionString="Server=mysql4.gear.host;Database=databasename;User Id=username; Password=password;" providerName="System.Data.SqlClient" />
However, when I publish the website I get a runtime error?
Runtime error:
Server Error in '/' Application.
Runtime 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".
<!-- Web.Config Configuration File -->
<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 configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
Console error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)

IMO, best place for learning to write connection strings is here: https://www.connectionstrings.com/sql-server/

Try this
<add name="UniversityContext" connectionString="Data Source=mysql4.gear.host;Initial Catalog=databasename;User ID=username;Password=password" />

I suggest to create file with .udl extension and test configuration.
It could help you to find proper parameters.

Related

How can I perform CRUD operations to a specific azure database in my Sql server object explorer and not a default connection database?

Connection String
<connectionStrings>
<add name="Connect"
connectionString="Server=tcp:players.database.windows.net,1433;Initial
Catalog=eManagerDB;Persist Security Info=False;User
ID=evanligon;Password=*******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" />
I know this connection string works because I am currently using it for the initial project that created the database in the first place.
I've already connected the database to my object explorer, I just can't seem to update it. I only seem to be updating a "default connection" database
When I launch it.
Web.Config
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
*PS This project runs perfect locally using the default database, so the code seems to be perfect.
You may need to publish your application and your database to Azure as explained here.

How to deploy ASP.net website on somee.com?

I am trying to deploy sample website on somee.com using free hosting.
First I published my website as a folder. I already tested on my local machine on IIS 7 in my local machine. That is working fine without any problem.
1. I created new free hosting domain on somee.com, then in file manager ->
2. Then I make a zip folder for my published website folder
3. Then I upload the zip folder and select upload and unzip archives
4. Now this is my root folder file structure
5. I hope it will run the default.aspx file. Then I try to visit my site it throws error like below
Error msg
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\b2d18bbc\3889fee\App_Web_home.master.cdcab7d2.cugbgmun.dll' -- 'Access is denied. '
Source Error:
[No relevant source lines]
Note
I created one small default.htm file for testing. If I upload that file. That's working fine.
Web.config file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
If I add the default.aspx file as a start up page on web config like below,
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="Default.aspx" />
</files>
</defaultDocument>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
Error msg
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Here are steps to publish your .net to the server:
Please open your project with Visual Studio tool
On the Solution Explorer windows (which is normally located on the top right hand corner of the VS tool), right click your project and select Publish
Please kindly publish it to a local folder, such as C:\Project
Please just upload whatever files/folders you see on C:\Project to the server via FTP and your site will work fine.
The steps will remain the same. If you face 500 internal server error, please ask somee to check full error message on the server.
In Web.confilg file turn on the customErrors
<system.web>
<customErrors mode="On">
</system.web>
now add connection string carefully .Only change provider connection value
<add name="DBModel" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;**provider connection string**='your database connection path'" providerName="System.Data.EntityClient" />

An application error occurred on the server

I am trying to access a aspx page from an IIS server. The page contains a registration form. The browser is opening the page, but when I am trying to enter values into the field and want to save it, it displays this 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 <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<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.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
What is the problem, and how do i fix it?
It seems that while saving some error is occuring and you are not getting that exact error.
So you have two options add below code.
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
or Use try catch in your save function and in the catch block put code to write enitire exception as string in a text file and then in text file you will have exact error.
But I would suggest first option.

Duplicate Connection String Error

I have a website deployed in a server. One day it threw an error saying the connection string name is already added. I checked the web.config file and it has only one entry in that name. I removed the entry from the config. Now the website worked well and fetched data from database.
Note: When I changed the name of the config file it show error.
I think, the issue is – the connectionstring part is cached in memory. Is it so? How can we overcome this unwanted behavior?
Config Files in Source Code
Release Config
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
Debug Config
<system.web>
</system.web>
REFERENCES:
Issue with unwanted connection string appearing in my published web config
.NET 2.0 App.Config connection strings includes unwanted SQLExpress default
That is not the issue - when you change the web.config file, the IIS process gets reset, so there can't be any caching involved.
What is more probable is that there is either a parent or child directory with a web.config file that contains the same connection string name - this is causing the error.
You can solve that in several ways:
Ensure there is only one web.config in the correct scope with the connection string name
Use the remove element:
<connectionStrings>
<remove name="theConnectionString" />
<add name="theConnectionString" ... />
<connectionStrings>
Refer Encrypted config file does not apply “remove” tag in connectionStrings for a related question

Azure Web Sites Config Error

I'm trying to deploy a mostly empty asp.net webforms app (with a custom httpmodule specified in web.config) to Azure and getting the following error:
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: An error occurred loading a configuration file:
Access to the path
'D:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\xqhbvcov.tmp' is
denied.
Source Error:
[No relevant source lines]
Source File:
D:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
Line: 0
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.276
Any ideas? I'm not sure what other information may be pertinent so if I'm missing something vital please ask and I'll supply it.
Entire web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--<httpModules>
<add name="AbcdModule" type="org.abcd.abcdHttpModule"/>
</httpModules>-->
</system.web>
<system.webServer>
<modules>
<add name="AbcdModule" type="org.abcd.abcdHttpModule"/>
</modules>
</system.webServer>
</configuration>
I had discussion with Windows Azure Websites team and found that custom HTTP Modules are supported with Windows Azure Websites so they should work and problem could occur depend on how complex the registration is.
For the sake of testing, I use the link below to create a custom HTTP Module and tested it in Azure Website which worked without any issue:
http://msdn.microsoft.com/en-us/library/ms227673%28v=VS.100%29.aspx
If you can provide more info about your custom HTTP Module (which seems to be part of org.abcd namspace and anything else) we sure can help. Alternatively you can submit the request at Azure Websites Forum, someone can help you directly.

Categories

Resources