instance failure error in asp.net web site - asp.net

I have a website included login module.when i hosted the website in iis there is an error
Server Error in "/" Application.
system.invalid operation Exception: Instance Failure
My ConnectionString is like this
<add name="MyConnectionstring" Connectionstring="Data Source=IP Address,1433;Network Library=DBMSSOCN;initial catalog=Databasename;integrated security=True" Provider Name="System.data.sqlclient"/>
How can i solve this problem?Any one knows Please help me

Simply change DataSource=My-PC\\\SqlServer2008 to DataSource=My-PC\SqlServer2008 in your Web config because the previous one is valid one you are writing in Code Beind file but not in Web config file as it is an XML file.

The first thing I noticed is that you need to replace IP Address in your connection string with the actual IP address and Databasename with the actual database name. You also don't need ",1433" after the IP Address since 1433 is the standard port.
Second, is the SQL you are connecting to the default instance on the machine? If it is a named instance, you need to make sure to include the name in the data source setting.
Third, does the ID the ASP.NET process is running under have authority to connect to the SQL Server instance?

Related

How to connect ASP.NET app to remote SQL Server

I need help connecting my Web App to a remote database (SQL Server).
I have tried many suggested solutions but I can't seem to come right.
This is how I connect to a local database, it works 100%:
<add name="DBCS" connectionString="Data Source=serverName;Initial Catalog=MVNE_Website;Integrated Security=True" providerName="System.Data.SqlClient" />
My ASP.NET Web App is hosted on one server, and the database is on a separate server.
The remote DB server is 100% configured to allow remote connections and firewall rules also adhere to the connection protocols. I think it is just my connection string that is incorrect but I don't know why??
Here it is(conn string for remote SQL server)
<add name="DBCS" connectionString="server=serverIP\serverName; database=MVNE_Website; Integrated Security=True" providerName="System.Data.SqlClient" />
I don't use a username or password when connecting to this remote SQL Server so I did not see a point in adding it in the conn string?
There can be a few reasons why this will not work. Here are 2 common ones:
Your web application will pass the username the application pool is running under, (which by default is some system user) to SQL Server. Change this to be a service account which has access to SQL Server.
If you are hopping across 2 or more servers to pass the credentials between IIS and SQL Server, you may need to implement Kerberos, which is a way to preserve the credentials. This is a complex network configuration thing.
Check point 1 first.
:/
In my web.config file custom errors mode was on RemoteOnly, so I turned it off and saw that my connection string was never the problem, the actual problem was that the app was trying to insert null into a primary key field that does not allow null, i never set the PK to auto increment
.. sorry and thanks

Active Directory membership provider using LDAP

I am working on a school assignment where we handle logins to a web application written in asp.NET using Active Directory. Our Active Directory is installed on a virtual machine on Azure.
When trying to login, I am presented with the following error:
I have checked my connection string multiple times, and can't seem to get it to work.
Currently, I have the following connection string:
<add name="ADConnectionString" connectionString="LDAP://ictforevents1.cloudapp.net/DC=ictforevents1,DC=cloudapp,DC=net" />
The DNS name assigned to our virtual machine is ictforevents1.cloudapp.net, which is also the domain I set up in the Active Directory setup wizard.
Using the data in the connection string above, I can connect to the AD using LDAP Admin.
How to fix the error?
I fixed the issue by replacing the domain with the IP address in the connection string. From what I could find, asp will always always try to use a secure connection, even when using the insecure port (389). It will not attempt this when an IP address is given.
My new connection string is:
<add name="ADConnectionString" connectionString="LDAP://23.97.173.160:389/CN=Users,DC=ictforevents1,DC=cloudapp,DC=net" />
While this is not ideal, because the server does not have a static IP, it's better than not working at all.

SQL connection string ignoring specified username & password?

I’m having a problem with my SQL Connection strings not using the authentication provided in the connection string. I have written an ASP.NET application using self-tracking entities and I need to access data from two different servers. The first server, SQLSERVER1 is using windows authentication and is on the domain and im able to pull my data just fine. The second server connection however, is on another box off the domain and I need to use a specific login and password to access the data. I confirmed that the credentials im using in the connection string can connect to the server just fine.
On my web-server setup I have my app pool in IIS7 running under its own credential “Domain\AppPoolUser”.
For some reason, whenever I try to call data from SQLSERVER2 after publishing to the webserver im getting the following error, even though I have specified the credentials in my connection string and they are valid. The connection works fine however, if im debugging the application locally : Login failed for user 'DOMAIN\AppPoolUser'.
It seems like it’s not using the credentials I have specified in the connection string, and instead trying to connect as the application pools credentials. How can I setup the connection string to use the credentials I have provided?
Here is my connection strings:
<add name="ADATrackingContext" providerName="System.Data.SqlClient" connectionString="Server=SQLSERVER1;Database=ADATracking;Integrated Security=True;" />
<add name="PatientContext" providerName="System.Data.SqlClient" connectionString="Server=SQLSERVER2;Database=Patients;uid=PatientUser;password=123456;Integrated Security=False;" />
Not sure if it matters, but the user should be User Id= and not uid=
The ADATrackingContext connection string will attempt to login using the Domain\AppPoolUser domain account since you have set the Integrated Security = true. Since you don't have Domain\AppPoolUser as a login for your db, you will get the error you describe.
Double check to make sure you are passing the correct connection string to your DbContext.
It looks like the error was being caused beacuse I was trying to pull the data before my client page was authenticated to the ADATracking connection string. I moved the data call over to the HomeConstroller.cs instead of the Global.asax file and all is working now. My mistake.

SQL Server 2008 connectionString question

I'm trying to connect to my SQL Server 2008 database with ASP.NET MVC 3. Here is my connection string:
<connectionStrings>
<add name="AppConnectionString"
connectionString="Data Source=(local);Initial Catalog=DatabaseName;User Id=UserName;Password=PassWord;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Any idea of what's wrong?
When I try to query something in my DbContext I get this exception:
$exception {"The provider did not return a ProviderManifestToken string."} System.Exception {System.Data.ProviderIncompatibleException}
InnerException {"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)"} System.Exception {System.Data.SqlClient.SqlException}
Could someone help me please?
Thanks
First check if your mssqlserver services are running fine. Just run net start mssqlserver in your command prompt.
Then try changing the connection string Data Source=(local) to Data Source=.
All the above is assuming that you have sql server installed in your local machine.
That error means that either the name of your Data Source in your connectionstring is wrong or that your sql server is not configured to allow remote connections : see here how to fix it.
Can you ping the server?
You can create a new empty text file, rename it to test.udl, double click on it and create your connection string that way. (A dialog will open and you can select provider, server, database etc).
also, have a look at www.connectionstrings.com for example connection strings
There is also the instance to take into account. eg if you use sqlexpress it may be (local)\SQLEXPRESS
Besides (local) try (localhost) or 127.0.0.1 (loopback address - and no place like ;-)
Also a single period will "." resolve to the local machine.
Your connection string and the advice above assumes that you are trying to connect to an unnamed, default instance. If your server instance is named then you need to include that as part of your conn string, like: .\ServerName
More great info can be found at: http://connectionstrings.com
I had a similar problem, and these are the steps that helped me:
1) Your application must have an App.config containing a connectionstring named with the same name as your class that inherited from DbContext. In my case "TestEF_CF.ProductContext".
<add name="TestEF_CF.ProductContext" connectionString="Data Source=localhost;Initial Catalog=ef_cf_test;Integrated Security=True" providerName="System.Data.SqlClient" />
2) The database cannot be created before you start to use it. Just set the Initial Catalogue to the name you want Entity Framework to create when it autocreate the database.
See my stackowerflow question for more information if you need it:
Entity Framework 4.1 Code First Freeze
If you look at the InnerException it's possible that what you actually have is a Login issue.
What I had to do to fix this was, change the account the DefaultAppPool runs as, to NetworkService (go to Advanced Settings and change Process Model, Identity) and then pick an account which has access to your database.
Assuming of course your app is running in IIS using the DefaultAppPool.
I made it NetworkService and granted the NT AUTHORITY\NETWORK SERVICE user access to my existing database.
This then allowed me to connect. My case might be specific but I thought I'd share just in case.
SqlConnection [object name];
[object name] = new SqlConnection("Data Source=Server_address/name;Initial Catalog=myDatabase;Integrated Security=True");
[object name].Open();
Note: The square brackets which is shown should not be putted, only object name have to be placed.
Server_address : Your Computer name.
myDatabase : your Database name.

Error: 40 - Could not open a connection to SQL Server - only on Staging website

I have two ASP.NET websites on a web-server, and two SQL Server databases.
I have a folder for Website #1, which contains a web.config with a connection string pointing to Database #1.
Under the folder for Website #1 there's a staging folder called 'staging', containing Website #2, and the web.config there has a connection string that points to Database #2.
Website #1 works perfectly.
But when I try to run Website 2, I always get 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I've verified that the connection string is correct and that it's pointing to Database #2.
But even when I swap in the connection string from Website #1, which works perfectly on Website #1, it still fails.
Here's what the connection string looks like:
<connectionStrings>
<add name="WebsiteConnectionString" connectionString="Data Source=localhost;Initial Catalog=WebsiteStaging;User Instance = false;User Id=xxxx;Password=yyyy" providerName="System.Data.SqlClient" />
</connectionStrings>
Is there anything unusual going on here that I'm not aware of?
Not sure which version of IIS you're using, but you might need to create two separate web applications: one pointing to the Website #1 folder and the other Website #2.
When you view Properties of the Website/virtual directory, the Application name should be set for both directories. Is this the case?
LOCALHOST is for IIS
(LOCAL) is for SQL Server
My connection strings usually say "Server=(LOCAL);Integrated Security=SSPI...."
I would check the security tab to find out the identity that both web sites are running under.
Really sorry... looks like it wasn't to do with the connection at all.
It was because the Linq-to-SQL data-layer (which was in another project) was referencing its own connection string (even though, wherever I instantiated a DataContext in the Website project, I always used the web.config connection string as a parameter).
But thanks for your answers, those would probably be good things to check, had the above not been the problem.

Resources