SQL Server not recognised after hosting the website - asp.net

I have hosted a website on somee.com and I'm getting the error which says that it is not able to connect to the sql server.
The web.config has the connectionstring as
<connectionStrings>
<add name="RegConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Can anybody let me know the changes I have to make to get this working?
P.S. I have uploaded the database in App_Data folder.

Your connection string still pointing to your local SQL server and even it is local database of your system.
You have to modify your connection strig before publishing the site to the external server/ hosted server.
Change the whole connection string and put below properties within it.
Data Source=value; Initial Catalog=value; User ID = value; Password = value;
Here Data Source will be your SQL Server IP address or URL.
Here Initial Catalog will be your Database name.
You have to put User ID and Password which you are using to your SQL Server (Not Local)

Lose this AttachDbFilename=|DataDirectory|\Database.mdf I have never used it
Try these name value pairs
Data Source=value; Initial Catalog=value; User ID = value; Password = value;

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

plesk panel using host user in Connection String in asp.net

I have developed a web apllication in asp.net with its connection String in web.config file and working very well in localhost. But when i deployed to hosting server using windows shared hosting it fives the error
Logic failed for user anama76
where anama76 is my domain user.My database userName is anama_Muneeb. I am finding it difficult to know that why connection string is using the domain user to connect to Db.
I have used connection in web.config to make sql server authentication
What is the solution
Your connection string must match the user name:
<add
name="ConnectionString"
connectionString="Data Source=your_database_server;Initial Catalog=your_database_name;User Id=anama_Muneeb;Password='your_password';"
providerName="System.Data.SqlClient"/>

Trouble connecting to SQL Server Express database

In my web application installed on IIS 7, I need to connect to a SQL Server Express database file (used for testing purposes only.) I use the following connection string in a web.config file:
<configuration>
<connectionStrings>
<add name="MyDbConnection" connectionString="data source=.\SQLEXPRESS;Integrated Security=true;AttachDBFilename='C:\Users\UserName\CSharp\WebApp004_TestDB\App_Data\Database1.mdf';User Instance=true;Connection Timeout=15" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I also set up NTFS permissions for the C:\Users\UserName\CSharp\WebApp004_TestDB\App_Data folder as such:
IIS_IUSRS = FullControl
IUSR = FullControl
NT SERVICE\MSSQL$SQLEXPRESS = FullControl
IIS AppPool\[MyAppPoolName] = FullControl
That still didn't help. When I try to connect to that database via my C# code I get an exception:
An attempt to attach an auto-named database for file
C:\Users\UserName\CSharp\WebApp004_TestDB\App_Data\Database1.mdf
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share.
Note that the same code works on another machine with the actual SQL Server installed (with a different connection string where I used DB user name and password.)
Any idea what am I missing here?
Have a look at this Connection Strings

ASP.NET A problem when connect from remote DB to localhost instance

I have made the remote database backup (MSSQL Server 2005 Express) to the localhost, and I want to connect with that in my app. To do so, I've changed the connection string:
from
Data Source=190.190.200.100;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
to
Data Source=TOMEK\SQLExpress;Database=myDataBase;User ID=myUsername;Password=myPassword;
but the error appears: Format of the initialization
string does not conform to specification starting at index 0
I can login to the Management studio with that login/pass, and also the user name that I login into sql server has role membership db_owner to that database
what's wrong with that connection string ?
Try one of the 2 options.
Data Source=foo\SQLExpress;Initial Catalog=bar;User Id=user;Password=pwd;
or
Server=foo\SQLExpress;Database=bar;User ID=user;Password=pwd;
They're equivalent, but not sure if you can mix/match
Server/Data Source
Database/Initial Catalog
Are you using a hardcoded string, or from a .config file? Does your username or pwd contain any characters that might need escaping in the .config file? i.e. slash, ampersand?
string connstr = #"Server=foo\SQLExpress;Database=bar;User ID=user;Password=pwd;";
SqlConnection conn = new SqlConnection(connstr);
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;Database=bar;User ID=user1;Password=&foo;"
providerName="System.Data.SqlClient" />
Maybe try comparing what you are doing to what is found here:
http://www.connectionstrings.com/sql-server-2005

instance failure error in asp.net web site

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?

Resources