Detached Database data source in web.config - asp.net

Good day.
I'm busy with a new website, but I am caught in a slight tangle.
How can I set up my data source in my web.config file to access the database listed in App_Data?
Here is what I tried. I am a little rusty with detached databases.
<connectionStrings>
<add name="Careers" providerName="System.Data.SqlClient" connectionString="AttachdbFilename=../|DataDirectory|/Careers_30March.mdf;user instance=true;Integrated Security=true;"/>
</connectionStrings>
This was my result:
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)
All I need is to access this database. I know how to read connection strings from the web.config to create a SqlConnection object. No usernames / passwords were allocated to this database.

Do take a look at this page. There are multiple examples on what can and cannot be used.

Related

Can't connect to SQL Server from asp.net application

Hi i want to publish my application in a IIS server.
First i create a database in my sql server and put all my needed data on it.
Then i update my web.config to use the new remote Database. Unfortunatly i get an error
ConnectionString:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IntranetDatabase;Data Source=SRVDEV2010\SRVDEV2010" />
Stacktrace :
[SqlException (0x80131904): 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.)]
I cheked if i can access database remotly. I create a udlfile to verify my connectionstring, Here is the result.
I don't know why the udl file can connect but not my application. Any help is appreciated
Under which user is the Application Pool configured to run? you're using Windows Authentication which means your IIS App pool should be configured to run under a user that has access to the DB.

how to access database kept in App_Data folder

I am getting problem while I try to access MS-SQL database that is kept in "App_Data" folder.
My connection string in web.config file is-
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\CRMDb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
The Exception is-
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)
Any relevant help would be highly appreciated.
Thanks in advance
First things first: do you have SQL Express installed on your machine? If not you can get it here for free.
If you do have SQL Express installed, check if your SQL Express instance is running. If it's not running, open a command prompt (as Administrator) and execute the following command:
net start mssql$sqlexpress

not able to registered user on sql membership on server?

I have successfully hosted my mvc website on server.
But I'm not able to registered new user.
I have used following connection string.
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Error is
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)
Using SQL membership tables for create user .
All going good on localhost but after hosting getting error.
Where I go wrong?
Sound like the aspnetdb.mdf file is not in the Data folder on the host can you confirm the App_Data directory and aspnetdb.mdf file exists on the host?
On remote server you need to change your connection string. Please user correct server url/ip and db name

unable to connect asp.net application with godaddy.com sql server database

I have domain on the godaddy.com. I have create the database over there.I am able to connect to the database from godaddy.com site with specified user name and password. but when i am going to use same information in my connection string in my asp.net web application on local machine it is showing
"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)"
This error.
my connectionstring is :
<add name="MyConnectionString"
connectionString="Data Source=myDataSource; Initial Catalog=MyDatabaseName; User ID=MyUserId; Password=MyPassword" providerName="System.Data.SqlClient" />
I have provided all required parameters to connection string here.I got this parameter information from godaddy.com database Description section.
You can't do that, their SQL server don't accept external connections.
[EDIT] OK, it seems that my first sentence is incorrect, look here:
http://community.godaddy.com/help/article/4978
http://community.godaddy.com/groups/web-hosting/forum/topic/ms-sql-remote-access/
http://help.godaddy.com/article/4977

A network-related or instance-specific error occurred while establishing a connection to SQL Server

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)
when i upload my site on webserver and connect with remote sqlserver2005 using connection string....
<connectionStrings>
<remove name="ConnectionString"/>
<add name="ConnectionString" connectionString="Data Source=69.16.253.19,1433;Initial Catalog=vb_usa;Persist Security Info=True;User ID=username;Password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
it produces the following errr --
you can see error in my webpage :
http://vbi.volvobusesindia.com
it shows an error above ..
i m using aspnetdb.mdf in my website in APP_Data Folder... features i use in my website is Login Control, Password recovery, signup control...
Tried all the above but did not work for me. When I checked Services, I found that the SQLExpress service which was set Automatic, was not started. Once I started the SQLExpress service, everything worked.
See the guide in this site http://www.connectionstrings.com/sql-server-2005
In particular look at the section on that page titled "Attach a database file, located in the data directory, on connect to a local SQL Server Express instance"
The format is:
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;
Database=dbname;Trusted_Connection=Yes;
Basically, you need to connect to the SQL Express instance installed on the web server and point it to where your database file is located.
On that remote machine (63.15.223.19), the SQL services are not running. You can go to that machine and try to run "net start mssqlserver" from command prompt.

Resources