We have an application which we are attempting to revive that was written in classic ASP in 2010. So far, I've done the following:
I created a Microsoft Server 2016 instance on Amazon EC2
I installed IIS Server
I created the website inside the IIS Manager, added/linked the files, and successfully ran the application on http://localhost
I installed SQL Server 2017 and imported the DB Backup (and successfully created the database)
I created a SQL Server user and tested that I can access the DB using the created database user
I enabled SQL Server Login Authentication and Windows Authentication Mode
I added the connection to IIS Manager.
I confirmed that web.config.xml has the proper information.
Im getting the following error:
2018-01-21 01:36:16 ::1 POST /intranet/process.asp |178|80004005|[Microsoft][ODBC_SQL_Server_Driver][DBNETLIB]SQL_Server_does_not_exist_or_access_denied. 80 - ::1
I noticed in the code theres a file that has a Session config for a database connection that doesnt look the same.
Im not sure what to do at this point. We need to figure out how to connect this database to the application
Heres my web.config.xml in the root:
<configuration>
<appSettings />
<connectionStrings>
<add connectionString="Server=server\SQLEXPRESS;Database=dbname;User ID=dbuser;Password=dbpass" name="SqlServer" />
</connectionStrings>
</configuration>
Here's my web.config.xml inside the intranet folder which is for an admin area:
<add name="WEB"
connectionString="Server=server\SQLEXPRESS;Database=dbname;User ID=dbuser;Password=dbpass"
providerName="System.Data.SqlClient" />
I noticed a file global.asa that has this:
Sub Session_OnStart
Session("ConnectString") = "Server=adifferentserver;Database=adifferentdatabase;UID=adifferentuser;PWD=adifferentpassword;Driver={SQL Server};"
This is my first time using ASP so you'd have to guide me for what other files you need.
The global.asa file in Classic ASP acts as an initialisation script it is commonplace to set long-running variables such as Application and Session variables there.
If this file contains a connection string variable then that is the value to change to your migrated database. At the moment process.asp is using Session("ConnectString") and ADODB is trying to locate adifferentserver using the SQL Server provider and failing. Once you correct the connection string using the required provider and server, database combination the page should work.
The other two values come from the web.config which was brought in with IIS 7.0 and above, it's designed for Microsoft .Net and Classic ASP does not know about connection strings configured inside it. The likelihood is there is another web application that uses ASP.Net that was making use of those connection strings.
Related
I'm working on a project using SQL Server 2008 Express. I had an instance called SQLEXPRESS and I used to connect to the DB via this connexion string :
<add name="MyConn" connectionString="metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;provider=System.Data.SqlClient;
provider connection string="data source=PCNAME\SQLEXPRESS;initial catalog=DbName;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This connection string was generated by .edmx file (I'm working on an ASP.NET MVC project, database first, and Entity Framework) and it worked fine.
I recently installed SQL Server 2016 with a Developer Licence. During the install process, I used the default instance, which is MSSQLSERVER. For information, the generated InstanceID is MSSQL13.MSSQLSERVER.
I have a SQL project in my solution to regenerate my tables on my new SQL Server; I could connect easily to the server via the wizard.
I also used SQL Server Management Studio to verify everything was fine on the server, and it works perfectly (tables are generated, connection was OK).
However, my code is unable to connect to the server and systematically failed to the first call with error 26 - can't locate server instance
Here is what I've tried so far:
Change the data source parameter of the connexion string to localhost , ., .\MSSQLSERVER, .\PCNAME, PCNAME.MSSQLSERVER, PCNAME.MSSQL13.MSSQLSERVER, DOMAIN.MSSQLSERVER, DOMAIN\PCNAME => Doesn't work
Verify SQL Service are running => They are
Create an .udp file, connect to my server, and copy/paste the generated connection string : Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=PCNAME => Doesn't work
Regenerate my .edmx file (and the connection stirng) => Doesn't work
Verify this suggestion => It was already correct
Why does all the connection wizards seems to work (SSMS,
.udl file, .edmx generator, my DB project), whereas my code is unable to reach the server? I didn't change any line of code.
EDIT : The crazy thing is I have a log database on the same server, the connexion string is
<add name="NLogConn" connectionString="Data Source=localhost;initial catalog=DBLOG;integrated security=True" providerName="System.Data.SqlClient" />
And it is actually logging the network error !! So is it really a connection string error or an EF error ? I'm using the latest EF version, 6.1.3 on each project referencing EF (The main and the DAL layers)
Before going off the deep end on what it could be let's start with a working connection string I just tested on my local machine on Visual Studio 2017 Enterprise with Entity Framework 6.1.3.
<connectionStrings>
<add name="TesterEntities" connectionString="metadata=res://*/Tester.csdl|res://*/Tester.ssdl|res://*/Tester.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=Tester;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
The marked up connection string is:
="data source=.;initial catalog=Tester;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"
For my test connection I am using my local server for a default instance also of 2016 developer edition(. is abbreviation for this). I am using integrated security and my database name(initial catalog) I am targeting is Tester.
There are a few things to consider if Entity Framework(EF) is not properly hitting a target.
What version of EF are you using? Before MS moved to Core, I believe the last .NET full edition of EF was 6.1.3. Ensure you are on the most current version on Nuget download.
If you go from Express to a full fledged SQL the connection string's 'provider' often will not be the same I believe. Or it could be the local default instance before sql is installed is different. Ensure you don't overwrite an existing connection string with this. The provider should be: 'provider=System.Data.SqlClient'
You are referencing a project of EF in ANOTHER project. Each project that references EF should be having the NuGet package for EF as well as a config file with the connection string. EG: I have a console project for testing things I write and reference another project called 'EF Testing' and I don't have an app config with a connection string. It won't work.
I am having a hard time in connecting my database to my MVC Application. I keep getting the following error, despite the recommendations that I have found online.
System.Data.SqlClient.SqlException: 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.
Background situation:
I have developed an MVC Web App with User database, and I would like to publish them on another computer. After copying the files to the host computer, however, I was unable to access the SQL Server, with the following error message: Error 50 Local Database runtime error occurred.
The followings are the steps I have taken from the start of publishing process to the end:
I have created an MVC Web Application on my personal computer, with a user login authentication as described in Rick Anderson's example: http://www.asp.net/mvc/overview/security/aspnet-mvc-5-app-with-sms-and-email-two-factor-authentication. Therefore, with the Web App, I have a default user database created with it.
I then deployed the App to my own C:/inetpub, by using Visual Studio 2013. The publishing method is "File System". I understand that Database publishing is not supported for this publish method. So after the Web App was published, I created a folder named "App_Data" in my C:/inetpub/wwwroot, and copied my mdf and log database from my Project folder in VS2013 into it.
Afterwards, I opened up IIS7 on my computer and set my Default Website's physical property to C:/inetpub/wwwroot. I opened my web browser and I could connect to both the website and my databse (meaning I can login through the website, and it manages to authenticate my login id). So it was all good when the web app was running on my computer.
Next, I had to install the Web App to the host computer where it will be hosted.
So I copied the whole MVC Folder (C:/inetpub/wwwroot) and put it in the host computer's C:/inetpub/wwwroot. Then I did the following settings:
In the host computer, I gave IIS_IUSRS read/write access to the database.
I opened MSSQL 2014 SSMS, connected to Server: (LocalDb)\MSSQLLocalDB, and added a new database, i.e. the database.mdf in my C:/inetpub/wwwroot/App_Data. So my user database is registered in SSMS.
The connection string in my IIS was then changed to (LocalDb)\MSSQLLocalDB because I have MSSQL 2014 installed on the host computer.
<add connectionString="Server=(LocalDb)\MSSQLLocalDB;Database=aspnet-MvcPWy-20140708072924;Integrated Security=true" name="DefaultConnection" providerName="System.Data.SqlClient" />
ApplicationPool settings for IIS7 was following this example
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
Despite all those configurations, however, I am still getting the same error. I would greatly appreciate if anyone could review my steps and see if I have made a mistake or missed some steps in setting this database. Thank you!
A network-related or instance-specific error occurred while establishing a connection to SQL Server
The main page loads fine, but the error occurs when I try to goto Account/Register or Account/Login.
The error occurs on this line in SimpleMembershipInitializer constructor in file Filters/InitializeSimpleMembershipAttribute.cs
if (!context.Database.Exists())
Now, if I set my web.config to
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />
</entityFramework>
it works locally only but I'm assuming it's using a local database. Right now my entity framework in the web.config looks like
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
I have another application where I am using the same hosting service and free database (appharbor and SQL Server Yocto) and it works just fine. I recently setup a new application and database and it doesn't work. I can connect to the database fine in SQL server and expanding the DataConnections -> MyContextName in visual studio 2012, so I know the connection string is not the problem.
I'm wondering if there is a problem on the server the database is hosted on and I don't have access to that.
I'm all out of ideas on how to fix this problem. Thanks.
The problem probably is that the connection string name hasn't been configured properly and/or doesn't follow the entity framework conventions (which differs a bit between Entity framework versions). If you can connect to the database from your own machine or from the SQL server admin page the problem is unlikely to be related to the database/database server itself.
Take a look at this discussion where another user experienced a similar issue. You might just need to set the right connection string name for the entity framework database context. Also make sure you have migrations set up to create the database.
This may explain why it's working locally with the local db connection factory. I suspect that a database is created in your local SQL server, and it can do so unrestricted. On AppHarbor you need to use the database and connection string provided since you can't create databases yourself. You can confirm whether that's the case by connecting to your local database server and listing the available databases.
I can also recommend using this sample application and the associated blog posts about running migrations and configuring entity framework (4.3) on AppHarbor.
first I have checked that Server Authentication is already set to:
"SQL server and Windows Authentication mode" (mixed mode)
้here 's my web.config connectionstring
<connectionStrings>
<add name="StockConnectionString" connectionString="Data Source=192.168.0.2;Initial Catalog=Stock;Persist Security Info=True;User ID=op;Password=operator" providerName="System.Data.SqlClient"/>
</connectionStrings>
Whene I test running (ctrl+F5) under VS2010 development this can connect to remote SQL server without any problem. but when i publish this project to local IIS (same web.config) an error occured..
Login failed for user 'op'. Reason:
Not associated with a trusted SQL
Server connection.
also i can connect to SQL server via SQL server Management Studio with SQL server authentication same user/pass.
no idea what's wrong with this.
finally, after 3 days can't figure this out. then i tried start over.
created a new project (ASP.NET MVC 2 web app) in VS2010.
go to Database Explorer > Add Connection..
use SQL server authentication to remote SQLserver directly instead of local.
then gotcha!! it told me..
this server version is not supported. you must have Microsoft SQL server 2005 or later.
my project was created under Win XP connect to SQLserver 2000 and it's work fine. now the answer for an error above is..
Visual Studio 2010 dropped support for SQL Server 2000. You'll either have to go back to VS2008/SL3, upgrade your SQL Server, or do things manually outside of Visual Studio.
...really appreciate this so much
Does it make any difference if you add this to the connection string ?
Trusted_Connection=False;
A clue is that it's saying that it's not trusted which indicates it's not using the username and password from the string. Has a connection string been possibly imported into IIS ?
Trusted is windows authentication which by the error is being used. Sql server authentication is username and password which you are trying to use.
So I'm moving my Asp.net mvc web app over to Arvixe shared hosting. This is the first time I've deployed an MVC app. I have been using SQL Server 2008 Express for the development database. Arvixe provides SQL Server 2008 or MySQL hosted databases.
A couple questions:
1.Can I use the mdf files from my Express database with the new Non-Express prodcution DB?
2.I'm having issues with my connection string. I changed the original web config connection string from this:
<add name="Database1ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
to this:
<add name="Database1ConnectionString" connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=ProdsDB"
providerName="System.Data.SqlClient" />
Now I'm getting this error:
Cannot open database "ProdsDB" requested by the login. The login failed
I have setup the database called "ProdsDB" through the Arvixe control panel and added one user. Do I need to add the credentials somewhere in the connection string?
Yes. You're going to need to add User Id=myUsername;Password=myPassword; to the connection string, and you'll need to remove Integrated Security=SSPI
Of course, you'll need to set them to the username and password you created. Also, sometimes hosting providers host the database on a separate server. If that's the case, you'll have to specify the servername in place of the dot.