Unable to connect to remote SQL Server 2005 - asp.net

I have created my asp.net website using database ASPNETDB.MDF but when I try to host my site on server ...
The SQL Server 2005 hosting provider issue me the
database name dobriyalji
server ip : 69.112.222.220
database username : XXXX
database password : XXXX
I have imported all of my ASPNETDB.MDF tables to my server database dobriyalji ...
And I empty the Appdata.mdf and aspnetdb.log file from App_Data Folder ...
When I try to run my site the following error occurs ...
An attempt to attach an auto-named database for file
Users\Ashish Dobriyal\Documents\Visual Studio
2008\WebSites\VOLVO\App_Data\ASPNETDB.MDF
failed. A database with the same name exists, or specified file cannot
be opened, or it is located on UNC share.
MY LOCALHOST CONNECTION STRING :
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
MY REMOTE HOST CONNECTION STRING :
<connectionStrings>
<add name="vbi_india2kConnectionString" connectionString="Data Source=69.112.222.220;Initial Catalog=dobriyalji;Persist Security Info=True;User ID=XXXX;Password=XXXX" providerName="System.Data.SqlClient"/>
</connectionStrings>

You have to use publish database wizard to deploy local database to your production database server.

Do you have the physical mdf / ldf files from your development machine. Assuming you do as the error "specified file cannot be opened" is quite clear. So are you on a shared SQL Server with other sites; if so is there a database on the sql server called aspnetdb? You may have to change the name of your database as you attach it in order to get it onto the sql server.
EXEC sp_attach_db #dbname = N'myASPNetDB',
#filename1 = N'c:\mypathdata\myaspnet.mdf',
#filename2 = N'c:\mypathlogs\myaspnet_log.ldf'

Related

Unable to complete operation. The supplied SqlConnection does not specify an initial catalog or AttachDBFileName

I am trying to create an App Service web app in the Azure Portal and to connect the web app to my local on-premises SQL Server database using the new Hybrid Connection feature.
Created a simple ASP.NET application using Visual Studio 2015 and trying to connect to the SQL server Database which is on on-prem. And modified the connection String as follows
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=PRAVEEN,1433; User ID=sa; Password=my_password;"
providerName="System.Data.SqlClient" />
</connectionStrings>
When the application is started its running without any errors as shown in below screenshot1.
But when I try register (enter any record) it throws me with an error as specified in the below Screenshot3....
"https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/" - this is the documentation to which I'm referring to..
So, can anyone from the other end help me out please...
Microsoft SQL Server Management Studio screenshot....
Thank you..
#Praveen,
It is what it says - meaning Initial Catalog is missing in your connection string. It requires the Db name to connect to. You have the servername, SQLUserName, SQLPassword, but missing the DatabaseName it requires. Please change your connection string to include the the DbName as follows
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=YourServerName,1433;Database="YourDbName" UserID=YourId;Password=YourPswd;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Look at this site to configure your connection string appropriately: http://www.connectionstrings.com/store-connection-string-in-webconfig/

ASP.NET MVC 4 connection string on server to mdf file on app_data for authentication db

I have mvc4 app on godaddy and I do not want to use their sql server database ....Actually I have exhausted my available number of databases on host
so i uploaded the authentication db file as mdf file to app_data folder but i cant connect the mdf file from my app
i used this conn string
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication3-20151212082404;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20151212082404.mdf" providerName="System.Data.SqlClient" />
it was working on local but not on server
so I changed it to this string
<add name="DefaultConnection" connectionString="Data Source=107.181.46.201\v11.0;Initial Catalog=aspnet-MvcApplication3-20151212082404;Integrated Security=SSPI ;user id=todd password=8534876523745;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20151212082404.mdf" providerName="System.Data.SqlClient" />
but it does not work
how can i connect my .mdf file
my mistake is that i was use a mysql database on godaddy
all what I did is that i create an empty sql server db and edit my connection string with the new db name and user and passwore

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

Cannot connect to mysql database in .NET MVC3

I've having some trouble in connecting mvc 3 application in .net. I know that mysql database instance has to be created before using web.config file to connect the it. My
connectionStrings as below:
<connectionStrings>
<add name="epmsDb"
connectionString="Server=localhost;Database=database1;
Uid=root;Pwd=mypassword"
providerName="System.Data.SqlClient" />
</connectionStrings>
and I've got a database name call epmsDb created in Server explorer. Then I tried to get the connectionString in the code using this :
string connectionString =
ConfigurationManager.ConnectionStrings["epmsDb"].ConnectionString;
context = new DataContext(connectionString);
usersTable = context.GetTable<UserObj>();
Every time I tried to access the database, I threw this exception:
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 been trying to overcome this for a week now. Does anyone have ideas why this occurres?
Your example tries to connect to an MS SQL database. To connect to a MySQL DB you might want to use the MySQL connector
Then change the ProviderName property:
<connectionStrings>
<add name="epmsDb"
connectionString="Server=localhost;Database=database1;
Uid=root;Pwd=mypassword"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>

MY ASPNETDB.MDF would not work in production server? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
Today i have create two pages login.aspx using LOgin control and register.aspx using Create user wizard ...
when i use connection string of my production server in my local computer then site works only if my database ASPNETDB.MDF is present in APP_Data Folder in my local computer..
if i rename ASPNETDB.MDF or Delete ASPNETDB.MDF from my local compuet App_Data the the following error occurs ...
An attempt to attach an auto-named database for file C:\Users\Ashish Dobriyal\Documents\Visual Studio 2008\WebSites\VOLVOO\App_Data\ASPNETDB.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
but
After i publish my webpages ..... and database to my production server .... it produces an 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
What was the problem actually ... ??
MY PRODUCTION SERVER CONNECTION STRING :
<connectionStrings>
<remove name="ConnectionString"/>
<add name="ConnectionString" connectionString="workstation id=volvobusesindia.mssql.somee.com;packet size=4096;user id=username;pwd=password;data source=dobriyal.mssql.somee.com;persist security info=False;initial catalog=dobriyal" providerName="System.Data.SqlClient"/>
</connectionStrings>
MY LOCAL SERVER CONNECTION STRING :
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
when i use connection string of my
production server in my local computer
then site works only if my database
ASPNETDB.MDF is present in APP_Data
Folder in my local computer..
This is because you need to add access permissions to the directory that you going to put the database. The permissions must be for the user that runs the asp.net pool that you using.
Alternative try this string, for both production and local server and just be sure that your database have the correct permissions for been access from the asp.net running pool account.
This is not depended from what you write on the string but from how you correctly setup the database. Its working 100% so if not play for you search the database permissions, both file and database settings.
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=localhost;Initial Catalog=dobriyal;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

Resources