I know its a classic problem, but I am too novice to even comprehend the basics (sorry). I have this ASP.NET "Website" with databases (SQL Server 2008), which I am trying to deploy on a Remote Host Server (HostGator) using WebSite Copy tool of VS 2010.
In VS 2010, I could grab the Connection string directly through the "property" of the database, which turned out to be:
Data
Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\myName\Documents\Visual
Studio 2010\WebSites\Experiment\App_Data\data.mdf";Integrated
Security=True;User Instance=True
Now, I know that a website called http://connectionstrings.com/ exists, but its too overwhelming for me at first glance.
My current connection string:
Data
Source=domainName.com\SQLEXPRESS;AttachDbFilename=C:\inetpub\vhosts\domainName\httpdocs\Experiment\App_Data\data.mdf;Integrated
Security=True;User Instance=True
I am pretty sure, that this is wrong as its giving me the classic error of:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server..
But I don't know how to fix it. Where to start looking, how to initiate, how to get the parameters required to build the connection string. How to find the path of the AttachDbFilename ? Can you please help?
I believe, that connection string is the only parameter which needs to be modified. If there's something else, then please suggest? Also, I keep coming across the usage of SQL Management Studio to make things work, I don't have that, so is it hard to accomplish this without it?
Please help, thanks.
You can't specify a directory relative to your own machine.
Change AttachDbFilename to
AttachDbFilename=|DataDirectory|data.mdf
The specifics for Data Source should be given to you from your hosting company, as well the security model (probably you need to use a specific user)
You can download SqlServer Management Studio Express from this link
Man,
What do you think about HttpServerUtility.MapPath Method. It returns the physical file path that corresponds to the specified virtual path on the Web server.
[]'s
When you get your hosting. They will provide the connection string for you. like this
<add name="ConnectionStringName"
connectionString="Data Source=localhost;Database=YourDatabaseName;Uid=YourUserNameForDatabase;password=yourpassword;"
providerName="System.Data.SqlClient" />
Let me know, if you need more help
Related
I've been given a site that was created by someone else and I'm now trying to test it. I can compile the system without any problems but when I try to log in to the website, I get the error:
"EntityException occured. A first chance exception of type 'System.Data.EntityException' occured in System.Data.Entity.dll. Additional info: The underlying provider failed on Open."
Furthermore, if I dig deeper, I see an InnerException of Cannot open database \"MyDB\" requested by the login. The login failed. Login failed for user 'name\\owner'.
I've read similar problems on the web and it seems like its a problem with database connections? I've tried multiple 'solutions' that include messing around with the connectionString but nothing works.
What I think the system wants to do is connect to a .mdf located in a separate project's App_Data. Anyway, here's the connectionString code that I received originally:
add name="NameServiceContext"
connectionString="Server=tcp:qiu5vg5yhv.database.windows.net,1433;Database=MyDB;User ID=MYID;Password=MYPASS;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
providerName="System.Data.SqlClient"
Quick question, what is the tcp:...... stuff? I'm assuming it was generated somehow, but how?
I've tried 'fixing' the problem and ended up with something like this:
add name="NameServiceContext"
connectionString="data source=./SQLEXPRESS;AttachDbFilename=C:\Users\owner\Documents\MyERP\App_Data\MyDB.mdf;Integrated Security=True;Connect Timeout=30;"
providerName="System.Data.SqlClient"
Both methods give the same errors and I'm out of ideas. How would I go about fixing this?
Also, when I connect to a db via tools>connect to database > MS SQL db file, I get an option between 2 data sources, ./SQLEXPRESS and (LocalDB)\v11.0. Do I have to include both of them? If so, how?
The original connection string refers to a Microsoft Azure instance. A typical connection string to Azure looks like:
Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[LoginForDb]#[serverName];Password=myPassword;Trusted_Connection=False;Encrypt=True;
Your server name is qiu5vg5yhv.database.windows.net. Most likely your credentials are incorrect.
It is as Andrew said, you don't seem to have access to the actual database. Simply download either "SQL Server Management Studio" or "SQL Server Management Studio Express" (depend on which version of database you are using) and try to connect.
If you connect successfully, check if you can query the database of your project.
If you connect unsuccessfully, contact your system admin to arrange access.
If you want to understand more about connectionstring or create one, use the following site for template: http://www.connectionstrings.com/sql-server/
You can get the necessary database details by viewing the Properties of your database via "SQL Server Management Studio" (right click and select Properties --> View Connection Properties)
I met the same question. The key step is here.
I used vs 2013 update 4.
When you configured your SQL in azure, it generated a connect string.
I am getting the following exception when I am trying to connect to a web service
System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file DatabaseName.mdb failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
The connection string I am using is:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|WS_Assignment.mdb;uid=Admin;pwd="
providerName="System.Data.OleDb"
I am trying to access SQL Server on local system.
I have gone through a lot of articles and followed all the different methods. But I got no solution.
Can anyone help me out?
Before Question was EDITED:
are you deploying on a web server , instead of your localhost. If thats the case you need to publish the sql script in Server DB as servers dont allow attachDB file in your deployment and if thats the case then your problem is solved.
After Update
you can always try with fullpath and yes you need OLEDB call not sql make sure thats not the case with your .cs code
Correction in your question:
i am trying to access SQL server On local system
:
i dont see how you can do that with .mdb file; even if thats not the case make sure sql services are running properly in your system go to->start button->program files->microsoft sql server yourversion-> configuration manager-> check running services.
In your Solution Explorer, click on "Show All Files". then go to your App_Data folder and delete WS_assignment.mdb and then run your application.
Also, your provider is wrong
providerName="System.Data.SqlClient" is the right one.
Secondly, your database name should end in .mdf or .sdf for SQL Server.
So, your connection string will become:
<connectionStrings>
<add name="ConnectionStringName"
connectionString="Data Source=|DataDirectory|WS_Assignment.sdf"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Check this.
http://msdn.microsoft.com/en-IN/library/5ybdbtte%28v=vs.71%29.aspx
using Access requires System.Data.OleDb library
newbie here.
I have a local db in my program. Whilst I was developing the program I used the SQL
Connection string :
SqlConnection sconn = new SqlConnection(#"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\leemk_000\Documents\......Integrated Security=True;User Instance=True;");
Now If I want to load this program onto a different computer I am sure that this connection will no longer work simply because it will still be looking for Users\Lee_000\
I have tried to remove Lee_000 but I get this following error:
An attempt to attach an auto-named database for file C:\Users\Documents..... failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
What can I do to get a connection string to work on different computers.
With many thanks
The whole User Instance and AttachDbFileName= approach is flawed - at best - especially when you want to share your database amongst multiple clients!
When running your app in Visual Studio, it will be copying around the .mdf file (from your App_Data directory to the output directory - typically .\bin\debug - where you app runs) and most likely, your INSERT works just fine - but you're just looking at the wrong .mdf file in the end!
If you want to stick with this approach, then try putting a breakpoint on the myConnection.Close() call - and then inspect the .mdf file with SQL Server Mgmt Studio Express - I'm almost certain your data is there.
The real solution in my opinion would be to
install SQL Server Express (and you've already done that anyway)
install SQL Server Management Studio Express
create your database in SSMS Express, give it a logical name (e.g. YourDatabase)
connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:
Data Source=.\\SQLEXPRESS;Database=YourDatabase;Integrated Security=True
and everything else is exactly the same as before...
If it's a local db you should be placing it within the app folder and carry it with the app right?
Put the database in the App_data folder of your app and use that in your connection string
<add name="YourConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\yourfile.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
You need to use a database server and let your users use it via your connection string like this;
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
"myServerAddress" should be the ip adress of your server machine.
I am continuing my previous question, as the reply lead to further doubts/points/concerns. I need help with the connection string on the web host server.
My connection string in the local computer is:
string connectionString = "Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\data.mdf;Integrated
Security=True;User Instance=True";
Now, I simply used the website copy tool with the VS 2010, and the entire website is copied as it is on the web host, with the database being at domainName/httpdocs/Experiment/App_Data/data.mdf
Now, I don't know how the complete connection string on the web hosting server look like. Some of the things which I learned, on the basis of those, I guess it should be:
string connectionString = "Data
Source=IP_Address_Of_WebHostingServer;AttachDbFilename=|DataDirectory|\data.mdf;User
ID=XXXX;Password=XXXX;User Instance=True";
Is it right (or COMPLETE?)? Also, I have no clue what the user id or password is? So on local computer, with the help of Integrated Security=True the windows authentication was being made. How to do it on the remote web host?
In the webhosting console, I see features such as create database, create database users, I can see the username and password aspects there. If those are required then how do I connect that with the database I just copied? It seems like those are the one's where database is created from scratch, while I already have the *.mdf (database) uploaded/copied.
I am stuck at this stage, and have no clue on how to proceed further. I know its something trivial, but out of scope of my knowledge. Please help me in completing the connection string. How do I make the database (data.mdf) file reachable/accessible?
I came across some articles which told to import the database and such (but where/why?), but I don't get it. When the database is in the App_Data folder, then why/how do I do that?
I am confused, please help.I'll highly appreciate step-by-step approach to fix it.Thanks.
EDIT (solution):
The solution given below is perfect. Apart from that this website/blog is worth checking.
-- http://www.asp.net/web-forms/tutorials/deployment/deploying-web-site-projects/asp-net-hosting-options-cs
And if you don't have SQL Management Studio, best way to install is instructed here:
-- http://blogs.msdn.com/b/bethmassi/archive/2011/02/18/step-by-step-installing-sql-server-management-studio-2008-express-after-visual-studio-2010.aspx
Step 1 - Create a DB Script from SQL Management Studio
You will need to firstly script off you database schema and data (not as scary as it sounds - follow the steps here http://blog.sqlauthority.com/2011/05/07/sql-server-2008-2008-r2-create-script-to-copy-database-schema-and-all-the-objects-data-schema-stored-procedure-functions-triggers-tables-views-constraints-and-all-other-database-objects/ ) .
Step 2 - Create your DB at HostGator and Import your DB Script
Create your database at HostGator and import your script file (Follow this guide here http://support.hostgator.com/articles/plesk/plesk-9/how-to-create-or-import-databases-plesk-9 ).
Step 3 - Update your connection string and deploy!
You'll need to update your connection string to be something like this (you will need to add your details).
<add name=”CRMConnectionString” connectionString=”Data Source=Server IP;Initial Catalog=DBName;User ID=UserName;Password=Pwd;” providerName=”System.Data.SqlClient”/>
This connection string was cribbed from this resource here http://asoftwaredeveloper.wordpress.com/2012/01/06/hostgator-web-hosting-and-mssql-db-access/
Then publish your website and upload your files. Its worth noting that you won't need to update your App_Data folder and its contents when you publish because you'll be pointing at the DB on their server not the one in your directory.
I've reviewed the post How to configure Fluent NHibernate with MySQL, but I'm relatively new to MySQL and I need to actually set up with connection string itself. I've installed MySQL as part of a WAMP install and need to fill in the actual connection string. Can someone help me by extending the linked answer to actually contain a full connection string example?
Appreciated.
Edit: I've tried several different things and I keep getting the following error message:
Can't load file FluentConfiguration.cs under d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg.
Check the file permission and the existence of that file.
I installed FNH via nuget, and I don't understand why it's looking at that path, as the d: drive is my CD and not a harddisk. Very confused.
The error you've pasted looks like Visual Studio trying to localise the sources to show you where the exception comes from. This is not the real exception message - you should have it somewhere there and it's probably something about wrong configuration.
If you've installed WAMP with default settings, it is configured to listen on 3306 port and have only local root account without password. So your connection string should look somehow like that:
Server=localhost; Port=3306; Database=[database_name_here]; Uid=root; Pwd=;
(Pwd= part may be not needed at all).
So you need to paste it in your App.config/Web.config's <connectionStrings> section:
<connectionStrings>
<add name="ConnectionString"
connectionString="Server=localhost; Port=3306;
Database=[database_name_here]; Uid=root; Pwd=;"
providerName="System.Data.SqlClient" />
</connectionStrings>
and then use the solution from linked question:
MySqlConfiguration.Standard.ConnectionString(
c => c.FromConnectionStringWithKey("ConnectionString")
)
Alternatively, you can paste the connection string directly in your Fluent's configuration, like this:
MySqlConfiguration.Standard
.ConnectionString.Is("Server=localhost; Port=3306;
Database=[database_name_here]; Uid=root; Pwd=;")
Anyway, this default root/no password configuration can be used only for local development and testing purposes.