I have this access.mdb at server folder. My webpage will connect to this access database using :
"Data Source=" & Server.MapPath("/cloud/login/mydatabase.mdb")
so the server path will be www.abc.com/cloud/login/mydatabase.mdb.
How can I connect to this database from my computer?
using C# or access
string connectionString = "PROVIDER=Microsoft.ACE.OLEDB.12;DATA SOURCE=www.abc.net/cloud/login/login.mdb;";
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
I tried connecting to server database using Access/ExternalData and point to the server path but I am unable to connect.
Reason why I am doing this is because when I change data, I need to use FTP to download this .mdb and change and upload back. Which is very troublesome.
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=\\serverName\cloud\login\login.mdb;
Note: The Server name is where you have ur mdb , so put that name. The folder which u access should be shared for access.
Related
I need to connect my app to MySQL via OLEDB. I wrote this:
oleDbConnection = new OleDbConnection();
oleDbConnection.ConnectionString = "Provider=MySQLProv; Data Source=myHostName; Initial Catalog=dmz_storage; User ID=myUserName; Password=myPassword;";
oleDbConnection.Open();
But I get an exception: Provider MySQLProv is not registered at the local computer. Of course, I add MySQL.Data.dll to my project. So how can I register MySQLProv? Or can I actually connect to MySQL via OLEDB?
I have a team project and I'm trying to publish the app at Azure, which I successfully did. I was able to get our database to Azure SQL server, but now I'm struggling with connecting the app with this database.
Originaly the app is working with a .mdf file locally, but now, when I'm publishing the app, I want to use the DB at azure server. I changed all the connection strings of .mdf file
(#"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =" + Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + #"..\..\..\PATH"))
in the code to the azure database connection string
(#"Data Source = Server=tcp:nameofserver.database.windows.net,1433;Initial Catalog=sqlmusicdb;Persist Security Info=False;User ID=...;Password=...;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")
but after publishing, the app is not connected to database, as it is writing
AN ERROR OCCURRED WHILE PROCESSING YOUR REQUEST
Any help, please? Thanx.
Your connection string is formatted incorrectly. Remove the
Data Source =
at the very beginning of your connection string and it should work.
I have a probleme with the database.
On my computer is working well but when i try to run it from other computer is not working.
This is connection string:
SqlConnection connection = new SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\OlxBotDataBase.mdf;Integrated Security=True");
I try to put database in %appdata% folder, but is not working or maybe i'm doing it wrong.
This is the error:
EDIT: I installed sql server, but now i get this error:
you can change permission for mdf and log file so that it can be accessed through your application
I found the solution.
I installed sql server express and atached the database and i modify connectionString like this:
connection = new SqlConnection(#"Data Source=localhost\SQLEXPRESS;Database=OlxBotDataBase;Integrated Security=True");
But i want to know if there is any way to automaticaly add database.
I define Sql_Cmd And Other sql variable that need before
and Now write this code:
string strConnection2 = "Data Source=.\\sqlexpress;AttachDbFilename=master.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection sqlcon2 = new SqlConnection(strConnection2);
string sql = "select * ";
Sql_Cmd.CommandType = CommandType.Text;
Sql_Cmd.CommandText = sql;
Sql_Cmd.Connection = sqlcon2;
try
{
sqlcon2.Open();
Sql_Cmd.ExecuteNonQuery();
}
catch (SqlException Error_Exception)
{
//FormError1 = new FormErrorInDataBase();
//FormError1.Show();
}
When I want to open sqlcon2 I see this error:
An attempt to attach an auto-named database for file master.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Please help me - how can I open master database and then use select query for this database, and what is the connection string for master.mdf?
Can I write the directory of mater.mdf such as C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\master.mdf or is it enough that I write AttachDbFilename=master.mdf?
Are you trying to open 'the' master database? The system database called 'master' is used internally by SQL Server and should not / does not need to be opened or attached in this way. If not, you'll have to call your database something other than 'master' - that is a reserved database name.
Check your parameters again. The right syntax to add an .mdf-file is as follows. Attach a database file on connect to a local SQL Server Express instance:
Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.
See: connectionstrings.com
master database is the system database that contains system information about SQL Server instance, information about databases contained in this instance and so on. This database is opened automatically when SQL Server starts.
So, when you want to connect to SQL Server, master database is already exist and cannot be attached. Information about this database you can see here
I cannot understand why you need to attach this database. Maybe you don't need to attach this database, but only connect to it? If so, you need to change th code:
string strConnection2 = "Data Source=.\\sqlexpress;initial catalog=master;Integrated Security=True;Connect Timeout=30;"
I want to connect to a database on a host except localhost, my DBMS is SQL Server and I'm using ado.net, like this:
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("insert into st (ID,Name) values ('"+cnt.ToString()+"','havijuri');", con);
//some sql commands.
con.Close();
what should I use as the constr (connection string), and with these information:
host IP: 10.15.10.12
the file is database1.mdf,
in this directory(on the host): D:\Project1\DataBase
Tell me if any other information is needed
If the mdf file is not attached to an instance of sql server and you want to connect to the database while it does not exist on the same machine as your application, you need first to copy the database to the server with the mentioned IP and attach it to an instance of sql server installed on that server.
The connection string in this case -if you have a domain and will be authenticated to the database server by windows authentication- will be as follows:
"data source=10.15.10.12; integrated security=SSPI;initial catalog=database1"
Or you can create a sql server user on the database sever and connect using the following connection string:
"data source=10.15.10.12; initial catalog=database1;user id=<username>;password=<password>"
http://www.connectionstrings.com/sql-server-2008
create a file on your desktop called test.udl open it up and follow the steps to connect to your database then click test to make sure it works. then open the file in notepad, it will be 1 line and contain the connection string
and with these information:
•host IP: 10.15.10.12 •the file is
database1.mdf, •in this directory(on
the host): D:\Project1\DataBase
You can not. Database file attachment is only supported by express, not by the real server. ForSL Server, you need the database name (which can be different than the file name) and the database must e mounted first by the DBA. You also need acces to the server (as in: username, password). The security credentials are - again - determined by the DBA.
So, you miss the critical information (name of the database, username, password) to access a database server.