Sql Server Error Caused by Web Part - asp.net

I am using webparts to create a dashboard page. To do that i am dynamically loading the webparts.
strZoneNumber = "zone" + intCnt.ToString();
UserControl UC = (UserControl)LoadControl(row["c_widget_path"].ToString());//Loads the usercontrol
UC.ID = row["c_widget_webid"].ToString();
UC.Attributes.Add("Title", row["c_widget_webid"].ToString());
//UC.Attributes.Add("title" , "Test");
GenericWebPart ucwebPart = wpmDashBoardManager.CreateWebPart(UC);//creates a webpart
wpmDashBoardManager.AddWebPart(ucwebPart, wpmDashBoardManager.Zones[strZoneNumber], ZoneIndex);//adds it to a zone
wpmDashBoardManager.Zones[strZoneNumber].Visible = true;
My webpartmanager personalization mode is set to 'true'
While running this page on the server it is giving me the following 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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory.
The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.**
Any ideas as to what might be causing this and solutions? Help would be greatly appreciated :):)

Many features of ASP.NET rely on intrinsic application services such as membership, roles, profiles, and personalization. For example, the ASP.NET personalization service uses a personalization provider to save personalized user settings on Web pages. By default Web Parts try to save personalizations into SQL Express database.
This solution was helpfull for me.
In connectionStrings section of your web.config file remove LocalSqlServer connection and add it again with your own preferences:
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="yourConnectionString" providerName="System.Data.SqlClient"/>
</connectionStrings>
Then if you will have 'Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion' error you should create a new database for you to use for personalization.
So, just explore C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe and go through steps of the wizard.
Hope it will help.

Related

Default account controller not creating database in MVC 5

I am creating a web application in ASP.NET MVC5. when i created the project a controller named AccountController was added automatically with all the necessary functions. now when i run the application and register a new user or try to login it gives some error. When i run it, it should create a database in App_data but its not creating any database and giving the following error. can anyone help me solve it please
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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
the connection string is:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-EmployeeOrderSystem-20160710042802.mdf;Initial Catalog=aspnet-EmployeeOrderSystem-20160710042802;Integrated Security=True" providerName="System.Data.SqlClient" />
if any other detail is needed please ask. Thanks in advance
When you create a new MVC 5 application and choose "Individual User Accounts", a new ASP.NET Identity Provider is included which uses Entity Framework 6 Code-First.When Identity is accessed for the first time, Entity Framework checks to see if the database exists. Unless configured otherwise, it uses the "DefaultConnection" to find the identity database. If the database does not exist when Identity is called, EF automatically created the database.When the first user is registered, database to be created.

trouble connecting to LocalDB in Visual Studio

I'm going through the Contoso University tutorial found here on asp.net and can't get past the first part due to connectionString problems.
I'm getting this error message after i enter the connection string and try to view the database.
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 was looking at this msdn blog which mentions the same error under the "Deploying LocalDB on IIS Server " section but i honestly have no idea what it wants me to do.
How can do i fix this error? Is it a problem with the tutorial or am I missing something?
Thanks in advance.
Any chance it is because you forgot to double-escape the backslash? Did you try this:
"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Or even better, you could just use the # mark to disable character escaping for the entire connection string:
#"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Here is what i do in order to fix this problem
You need to install the sql server local db
Copy the local server of your local db in case you don't know here is how to find the local server name(You need to copy the highlighted part)
Update the local server name in the connection string in the web.config file of the Contoso Project
Note that you only need to update the server name in you connection string do not replace the whole connection string with the server name.
Re run all the migration one by one like this
update-database -TargetMigration MigratonName
Build the project and run it.
Change application pool identity from ApplicationPoolIdentity to LocalSystem in IIS for your website application pool and IntgretedSecurity = true in config
will help you.

Cannot create SQL Server DB within Amazon RDS Instance

This seems to be a common question, however I haven't found a solution out there and many related questions are quite vague. Anyways, I am deploying an ASP.NET MVC 5 application to AWS using the AWS toolkit for Visual Studio Pro 2013. I have successfully published the app to Elastic Beanstalk with the exception of my database file which exists as a localDB database (.mdf). In trying to migrate this (very small) database I have created an RDS DB instance for SQL Server Express. My issue is that I cannot create a SQL Server DB which appears to be a common issue for VS users: I right click on the DB instance, select "Create SQL Server Database", VS is busy for a few moments and then nothing happens.
What I have done thus far:
I have an RDS instance created on a VPC with a security group that has an Inbound rule set to allow all traffic from my IP
I have an IAM user account with the following policies: PowerUserAccess, AmazonS3FullAccess, AmazonVPCFullAccess (I imagine some of this is redundant-I added additional policies to see if it was a permission issue)
So to succinctly state my questions, why is Visual Studio failing to create the SQL Server DB within the database instance? Or alternatively, is there a simpler method of migrating my database to AWS?
Just FYI, these are the references I have been using to deploy my application:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_NET.quickstart.html
https://aws.amazon.com/blogs/aws/net-support-for-aws-elastic-beanstalk-amazon-rds-for-sql-server-/
I'm brand new at AWS so let me know if clarification is needed.
Update: I checked the logs for my instance and I'm getting error logs
2014-12-12 18:16:02.72 Server The SQL Server Network Interface library could not register the Service Principal Name (SPN) [ MSSQLSvc/AMAZONA-E3AJMJI ] for the SQL Server service. Windows return code: 0xffffffff, state: 53. Failure to register a SPN might cause integrated authentication to use NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies and if the SPN has not been manually registered.
And
2014-12-12 18:47:23.72 Logon Error: 17806, Severity: 20, State: 14.
2014-12-12 18:47:23.72 Logon SSPI handshake failed with error code 0x8009030c, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure. The logon attempt failed [CLIENT: 113.108.150.211]
2014-12-12 18:47:23.73 Logon Error: 18452, Severity: 14, State: 1.
2014-12-12 18:47:23.73 Logon Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. [CLIENT: 113.108.150.211]
UPDATE: Issue solved. We use a proxy server in my office which seemed to cause authentication with the RDS instance to fail, not allowing me to connect from my machine. I accepted Ossman's answer as I think it solves a lot of similar questions I've come across trying to solve this.
This is a AWS explorer for Visual Studio 2013 bug and actually occurs because you're using the "default security group" by default when you're creating your DB instance in RDS.
Access the EC2 Service in AWS Management Console.
Click on "Security Groups", and then on "Create Security Group"
Give it a Name, Description and use "vpc-0846aa61" as VPC.
And then add following rule for both "Inbound" and "OutBound" rules
Type: "All traffic"
Source (for Inbound): "Anywhere"
Destination (for Outbound): "Anywhere"
Then Create the Security Group
Go back to your DB Instance and then change the "default" security group to the one you just created. This is done by clicking "Instance Actions" and then "Modify".
Then you should be able to see following window when you right click on your instance in Visual Studio and clicking on "Create SQL Server Database":
My DB Instance:

Database is not accessible on server but working well on localhost

I have developed my first website in ASP.NET with C#. It's a small website which uses Microsoft SQL server 2008 for database and I've deployed it on a free hosting site www.somee.com. It's database is working well on my computer but when I try to access the database on server it gives following 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)].
I have updated connection string of the database in web.config and I've used getConString() method for accessing connection string like this:
public string getConString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
}
What can I do to solve this problem.
Wbsite url is: www.easyways.somee.com
Thanks all of you for your support. I got the solution for my problem. Actually I did something wrong either in creating a database or in using connection string.
Now I recreated a blank database and then I executed the SQL script that I created for my database by navigating to "User -> Managed products -> MS SQL -> Databases -> (Database name) -> New SQL query from file". And also updated the new connection string in web.config file.
This is the connection string I used now:
"workstation id=dataeasyways.mssql.somee.com;packet size=4096;user id=easyways_db;pwd=********;data source=dataeasyways.mssql.somee.com;persist security info=False;initial catalog=dataeasyways"
Your hosting provider provides the connection information for you (in the case of your hosting provider you can see their Help Page here, which shows you how to connect to their DB.
Basically it boils down to logging into their control panel.
In "User menu" navigate to "User -> Managed products -> MS SQL -> Databases -> (Database name)".
Also remember that since this is a remote database there is a small chance that its firwalled from the outside world and only local webservers can access the database.

working with sql server 2008

I am not used to work with SQL Server(usually I just use express). I run it on windows server 2008, iis7.
I have attached the database to my sql server. I made a web site in iis7 but I get this error message.
Cannot open database "Phaeton.mdf" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Connectionstring I use
<add key="PhaetonConnectionString" value="Data Source=.;Initial Catalog=Phaeton.mdf;Integrated Security=True"/>
Thanks
Since you are using Integrated Security the SQL connection will use the windows identity which is passed from ASP.NET.
You can either change your security to mixed-mode which will involve removing the integrated security. Or use impersonation (check IIS and your web.config) and grant that user access to the database.
Hope that helps
You need to configure your application in IIS to turn off anonymous access and turn on Windows authentication(If yoy want to use integrated security).
Access SQL Server Using Windows Integrated Security
The other way, you can use a connection string with user/password ... with the appropriate login
Problem was that the database I tried to attach was sql express
The problem is here:
Initial Catalog=Phaeton.mdf
In SQL Server Express, you can attach a filename as a local database. That's not how it works on a production SQL Server. In non-Express versions you attach a database permanently, which it looks like you've already done, and you give it a logical name, which is not the same as the primary file name.
I would guess that if the file name was "Phaeton.mdf" then you probably named the database "Phaeton". In which case that part of the connection string should simply be:
Initial Catalog=Phaeton
If that's not the right name, you can get a list of database names from the server using the following script:
USE master;
SELECT name FROM sys.databases

Resources