I am trying to write C# code to access a database using odbc commands, the database is not local.
My connection string looks like that:
Driver={SQL Server};Server=serverName;Database=dbname;UID=username;PWD=apassword;
Somehow I cannot get the connection to open....
Can someone explain why? am i missing something in the string?
Try this ODBC connection string:
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
as described here
Related
I'm a beginner so I'll try to explain what I'm trying to do so please bear with me:
I'm developing a db application on C# and I'm using MySQL (Workbench) to manage my database so when I establish the connection in the C# project I use the following connection string:
string MyConnectionString = "Server=localhost;Database=catalogue;Uid=root;Pwd=1234;";
But I'd like to send the project to a friend to check it out so what would be the easiest way to send him the DB as well? Is there a way to send it as a single file (something like an Access db) and modify the connection string so that the project works without him adding the db to the localhost.
Thank you!
How can I connect my Trgovina.mdf with dataGridView?
I follow this tutorial, but it seems that program doesn't find my database.
Connection string looks like that:
string connString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Klemen\documents\visual studio 2012\Projects\Trgovina\Trgovina\Trgovina.mdf;Integrated Security=True";
Everything else is the same as tutorial example.
Error string is An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'
Full code looks like this.
The tutorial you talk about in your question use an Access Database and thus uses the OleDB engine to reach and work with the database. Instead your connection string use the syntax reserved for SQLServer LocalDB.
You should change your objects to SqlConnection (instead of OleDbConnection), SqlCommand (instead of OleDbCommand) and so on...
With these changes you should be able to connect to the automatic instance of SqlServer LocalDB. The rest of the tutorial could work or not, depending on what is present in the MDF file used.
You trying to connect to database .mdf file, but you have a wrong provider.
An MDF is a Microsoft SQL Server database not a Jet Database like
Access (*.mdb). You cannot just connect to the flat file and read it.
You would need to mount the database in an instance of SQL Server.
You could install SQL Server 2005 Express
Source
Note: Just download MS SQL Server 2005 Express or later and you must use the System.Data.SqlClient instead of OLE DB to solve your problem.
I'm trying to access Oracle 11g DB.
According to connectionstring.com , the connstring should be :
Driver={Oracle in OraClient11g_home1};Dbq=myTNSServiceName;Uid=user;Pwd=passwd;
Anyhow I'm getting an ArgumentException: 'Driver' is not a valid word.
Thank you.
Greetings
R. Bada
It looks like you are trying to use connection string which is suitable in case of ODBC drivers for Oracle.
You should look for connection string suitable for ODP.NET in Oracle Data Provider for .NET / ODP.NET section. The best is to use one of the following:
Data Source=TNSServiceName;User Id=user;Password=passwd;
or
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=user;Password=passwd;
The first is suitable when you are using TNS, the second allows you to provide the service definition in connection string.
How to create connection to database in VS2010 without SQL Client dynamically?
I tried using ConnectionStringSettings and SqlConnection and I succeeded, but I'm not supposed to use SQL Client.
I'm using Massive.
You should be able to use System.Data.OleDb.OleDbConnection.
Use a connection string like this:
Provider=SQLOLEDB;Server=myServerAddress;Database=myDataBase;Uid=myUsername; Pwd=myPassword;
It might be that you just miss to reference System.Configuration in your project and consequently Massive cannot find the connection string in your app.config.
Following the instructions on github I could query my SQL Express database without any problems using Massive having a plain SqlClient connection string in my app.config.
I have a system DSN.How to connect to the database in asp.net using DSN.I wanted the Connection String
Check out the link , has both DSN and DSN less ODBC connectivity using ADO.Net
http://www.easysoft.com/developer/languages/csharp/ado-net-odbc.html
One way of finding out the connection string is to create a connection in Server Explorer in Visual Studio, then check the properties of the connection and you will see a Connection String property that will give you what you need.