Unable to connect to SQL Server database - asp.net

When I click the Security tab on the ASP.NET Web Site Administration Tool, I get this error.
"Unable to connect to SQL Server database.".
I'm using Visual Studio 2012
<configuration>
<connectionStrings>
<add name="devices" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\devices.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="users" connectionString="Data Source=(LocalDB)\v11.0;AttachDbfilename=|DataDirectory|\database.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>

Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\devices.mdf;Integrated Security=True
Looking at your data source. Does (LocalDB)\v11.0 exist and can you connect to the above DB?
If not that will be the reason....
I have found that every time I create a package for my website (For manual deployments), it overwrites my connection string in the package being created with the above data source.
This can be a blessing some times preventing your new website from launching. (Especially if its in the wrong environment. :)
http://www.connectionstrings.com/ This site is great for helping you creating connection strings for almost any DB.

Related

Website can't connect to database on smarterasp.net webserver - possible error in connection string

I am getting a problem when I try to connect from my website to my database on my webserver (smarterasp.net). Everything works fine on the local host, then I uploaded the site to smarterasp.net and created the database there, now the site can't connect to the database, here is what I have in my web.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="UsersConnectionString1" connectionString="Data Source=MYSQL5012.Smarterasp.net;Initial Catalog=db_9df63f_active;Uid=9df63f_active;Pwd=MYPASSWORD; "
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
Where password obviously includes my real password.
Here is what smarterasp.net provided as the connection string:
ASP.net "Server=MYSQL5012.Smarterasp.net;Database=db_9df63f_active;Uid=9df63f_active;Pwd=YOUR_DB_PASSWORD;"
Classic ASP "Driver={MySQL ODBC 5.1 Driver};Server=MYSQL5012.Smarterasp.net;Database=db_9df63f_active;Uid=9df63f_active;Password=YOUR_DB_PASSWORD;"
I also tried putting the connection string in the web.config file as connectionString= "Server=MYSQL5012.Smarterasp.net; Database=db_9df63f_active; Uid=9df63f_active; Pwd=MYPASSWORD;"
but this didn't work either.
Appreciate any help. Thanks!
It looks like smarterasp.net does not allow remote database connections if you dont have a premium account.
to solve that problem , after you publish your website, navigate to the file manager , on the root of your files on your website , there is a webconfig , edit it and modify the connection string there , replace it with the connection string given to you by the website database section.
on the websites webconfig file

ASP.NET Web Site Administration Security section: Unable to connect to SQL Server database

I am developing an ASP.NET application using MS VS 2013 and MS SQL Server 2014.
When i start ASP.NET Web Site Administration Tool by CMD and click on security tab, I get below error:
" There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database. "
my web.config setting:
<configuration>
<connectionStrings>
<add name="newsdbConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\newsdb.mdf;Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
What is the problem .
Try below connection string and check.
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
Trusted_Connection=Yes;
Server=(localdb)\v11.0;Integrated Security=true;
AttachDbFileName==|DataDirectory|mydbfile.mdf;
And ensure that mdf file is located in published App_Data folder.

Setting Up Connection String of Visual Studio Built in SQL file to ASP.Net?

I added database file to my built in sql server of Visual Studio and i have also connection string of it but i am confuse how to add this connection string into web.config
here is my try to add connection string to code below :
<connectionStrings>
<add name="myFirstConnectionString" connectionString="Data Source= .\SQLEXPRESS;AttachDbFilename="C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf"; Integrated Security=True;Connect Timeout=30;User Instance=TrueproviderName="System.Data.SqlClient" />
</connectionStrings>
I am much confused that how i can add connection string of my visual studio built in database file to web.config.
Please help me as i am new in asp.net and ignore my way of asking.
To make your connection string work with the path you've given, it should look somewhat like this:
Visual Studio 2012 (SQL Server 2012):
<connectionStrings>
<add name="myFirstConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;Integrated Security=True;AttachDBFilename="C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf";Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Visual Studio 2010 (SQL Server 2010):
<connectionStrings>
<add name="myFirstConnectionString"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename="C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf";User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
But you should consider moving the database file to the App_Data folder in your project, and then use AttachDBFilename=|DataDirectory|MyFirstTask.mdf instead.
You should place you .mdf in App_Data folder, then you can use this
<connectionStrings>
<add name="myFirstConnectionString"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|MyFirstTask.mdf;
User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
With C:\Users\Ahdus\Desktop\First Task\First Task\MyFirstTask.mdf, if you move your application to another machine, that path might not exist
|DataDirectory| maps to your application App_Data folder

ASP.NET Sql Provider

I got a problem. When i'm creating the new project in ASP.NET using VS 2010, it's web.config with a default connection string about SQL Express created. But i haven't even got SQL Express installed. What should i do to change the default AspNetSqlProvider to work with my instance of full-weight SQL Server as a services database? And how can i change the template for the ASP.NET project to create a project with my connection?
You mean this one:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
To change this into one that'll work with SQL Server, it needs to look more like this:
<add name="ApplicationServices"
connectionString="data source=ServerName;Initial Catalog=DatabaseName"
providerName="System.Data.SqlClient" />
where DatabaseName is probably aspnetdb. It'll need some form of authentication, whether you use Windows authentication (in which case you can copy the Integrated Security element from the original connection string) or SQL Server authentication (where you'll have a username/password combination).
There's great info on building connection strings at connectionstrings.com.
To fix this for your future projects, you'll need to change the template for Web Projects. Locate the folder where your C# Web templates are kept (for me this is C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033.
Take a copy of the WebApplicationProject40.zip file (you might also want to backup the original somewhere!).
Inside it you'll find the web.config file with the SQL Express connection string. Change it to a SQL Server string, and then re-assemble the zip file.
The last step is to rebuild the VS template cache - from a command-line (VS Command Prompt probably works best), run devenv /installvstemplates. See here for details.
I just had a similar problem. I had a web site created in VS 2008 and wanted to try web parts. Added some to a page, then started getting:
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.
I ran aspnet_regsql.exe (wizard, in .Net framework folder) to create the database and then I added a connection string to web.config:
<configuration>
<connectionStrings>
<add name="aspnet_membership" connectionString="Data Source=localhost; Initial Catalog=aspnetdb; Integrated Security=SSPI;"/>
</connectionStrings>
</configuration>
Then I added this to web.config:
<configuration>
<system.web>
<webParts>
<personalization defaultProvider="SqlPersonalizationProvider">
<providers>
<add name="SqlPersonalizationProvider"
type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
connectionStringName="aspnet_membership"
applicationName="/" />
</providers>
<authorization>
<deny users="*" verbs="enterSharedScope" />
<allow users="*" verbs="modifyState" />
</authorization>
</personalization>
</webParts>
</system.web>
</configuration>

Godaddy ASP.NET membership database woes

I purchased a Windows shared hosting account on godaddy that came with 2 MSSQL databases. I setup one to hold my site data and the other installed aspnet membership schema to store site members. The site works perfectly even displaying data from the 1st database. However when I try to login or register I get this nasty error
Exception Details:
System.Configuration.Provider.ProviderException:
The SSE Provider did not find the
database file specified in the
connection string. At the configured
trust level (below High trust level),
the SSE provider can not automatically
create the database file.
Ive gone through my web.config and there's nothing wrong with my 2 connection strings. It seems godaddy has a problem with using 2 mssql databases simultaneously when 1 is for membership.
Does anyone know a solution or a workaround?
I hope my experience benefits every one. Basically if you want to avoid aspnet membership problems on godaddy always use "LocalSqlServer" as the connectionstring. i.e
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" connectionStringName="LocalSqlServer"
..other attributes here... />
</providers>
Then create the "LocalSqlServer" connectionString...remember to remove it first
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=xxxx; Initial Catalog=xxx; User ID=xxx; Password=xxx;"
providerName="System.Data.SqlClient" />
</connectionStrings>
I ran into same problem and am using MVC3. Above solution works but with some other changes in MVC3. It took me long time to figure it out so if anybody has similar issue in MVC3 it might help them:
Search for "connectionStringName" in web.config and replace the name with connectionStringName="LocalSqlServer"
Also under connectionstrings make sure
-To add (As this is important for all who are using shared hosting it will replace machine.config LocalSqlServer connectionstring with yours.)
-Keep your current connectionstring (In my case it is FilmiDb, this is required for you to connect to the database in EF model. Without this you will get errors.)
<connectionStrings>
<remove name ="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Initial Catalog=SofilmiDb;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="FilmiDb" connectionString="Data Source=.\SQLExpress;Initial Catalog=FilmiDb;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>

Resources