How do I get provider name to open Ole DB connection? - c#

So I have a client program and a database on sql server that's on my pc (localdb). I'm trying to set connection on, but it seems like provider is wrong. My connection string looks like this:
connection.ConnectionString =
"Data Source=(localdb)\\Projects;" +
"Provider=MSIDXS;" +
"Initial Catalog=TermPaperWork;" +
"User id=DAZZBOURGH\\Dazzbourgh;" +
"Integrated Security=True;" +
"Password=;";
So everything is OK there, except provider. I don't get what it is and how to use it and how to know which provider suits my database.
How do I find out my provider for exact base?

I always use http://www.connectionstrings.com when I have questions on the format of a connection string.

Related

Unable to load database from local server location in C# Connection String (windows application)

I'm trying to do application to access the database from local file server, but the connection string does not recognize the server location. This is a windows form application, using sqlite. Kindly help me on this one.
File server location will be like this:
\\fileserver\Testdb\maindb.db
Code used:
string server_database_path = #"\\fileserver\Testdb\maindb.db";
string connection_data = "Data Source=" + server_database_path ;
using (var conn = new SQLiteConnection(connection_data))
{
conn.Open();
SQLiteCommand insert_Rec = new SQLiteCommand(query_text, conn);
insert_Rec.ExecuteNonQuery();
conn.Close();
}
Error:
Unable to open database file
I may be wrong but I dont think that directly specifying the .db is correct. When using a normal SQL Server I would specify the instance (or just the server hosting it if it was the default instance).
So, your connection string should look something like
string connectionString = "Data Source=192.168.0.1; User ID=administrator; Password=YOURPASSWORD"
or if you are connecting the machine you are on it should be
string connectionString = "Data Source=127.0.0.1; User ID=administrator; Password=YOURPASSWORD"
You could substitute the 127.0.0.1 for \\localhost
I was confused in doing this, but by changing the slash "\" to "/" it really worked.
When i changed the slash in the path string it started to work fine and everything goes well.
Example: #"//fileserver/Testdb/maindb.db"

Unable to read local SQL Server file when running as exe. Works in IDE

This is the first time that I am trying to use a SQL Server File type database. It works when I run in the IDE but when I double click on the exe or right mouse click "Run Elevated," I get an error when trying to connect.
The message box displays the same connection string when running in both modes.
What might be the issue? Some sort of permissions issue?
MessageBox.Show(ApplicationParameter.LocalDatabaseConnectionString);
databaseConnection = new SqlConnection(ApplicationParameter.LocalDatabaseConnectionString);
databaseConnection.Open();
I get the following SqlException:
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: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.
Here is the connectionstring from the app.config file:
<connectionStrings>
<add name="LocalDatabase" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=C:\MYCODE\MyCompany.DISKMONITOR\MyCompany.DISKMONITOR\DATA\DATABASE.MDF;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"/>
</connectionStrings>
And my class for reading the app config:
class ApplicationParameter
{
public static string LocalDatabaseConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings["LocalDatabase"].ConnectionString;
}
}
}
Update:
I ran as Administrator and got the same result.
Connections.Classified contains information specific to the location of the db, what instance to use and username/password information. Will not be posted...
Here is my SQLConnections.cs class that I use in all of my apps (well mine is oracle I've just updated it to work with SQL):
private String connectionString = "Server=" + SERVER + "\\" + INSTANCE + ";Database=" + DATABASE + ";User Id="+ USER + ";Password=" + PASSWORD + ";"
protected SQLConnection getConnection()
{
return new SQLConnection(connectionString);
}
In use in a repo class that extends the Connections.SQLConnections:
SQLConnection connection = getConnection();
A lot less clutter and easier for someone else, reading your code, to understand.

Why ConnectionString fails for SqlConnection using MSN example in C#?

I am using the following tutorial example verbatim:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx
The error message is that the connection failed. "Modify it to connect to a Norhtwinf=d database accessible to your system."
string connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
SqlConnection northwindConnection = new SqlConnection(connectionString);
northwindConnection.Open();
As far as Northwind Database, I downloaded it from this website and I ran it.
http://www.microsoft.com/download/en/details.aspx?id=23654
Would you be able to tell what am I doing wrong?
Data Source property needs to point to your SQL instance name, and if your SQL instance is the default one.
I know that the next suggestion is a little weird and looks like the same that you are using, but try and let me know what happened:
string connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=.";
note that I've modified the Data Source value from 'localhost' to a (dot).
Make sure the account has access to that database, and try using this connection string:
connectionString="Server=MACHINE-NAME\SQLEXPRESS;Database=Northwind;Trusted_Connection=True;"

C# Error in accessing an Access Database over LAN

Here's my connection string:
sConnection = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\" + lstNet.SelectedItem.ToString() + "\SharedDocs\Documents\Debug\App_File\ggbase.mdb;Jet OLEDB:Database Password=g3n3r4l;";
lstNet is a listbox that contains all computers found in the network.
I'm assuming something else is wrong with my connection string.
According to Connection Strings website, to access a database over LAN, the following connection string format is used:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\serverName\shareName\folder\myDatabase.mdb;User Id=admin;Password=;
I'm assuming that shareName is where my Connection String fails. What is a shareName? And what are the shareNames of Windows XP and Windows Vista / 7 if, say, I placed my database in their Shared Documents / Public Files?
I've tried modifying my connection string into the following:
\C$\Users\Public\Documents\Debug\App_File\ggbase.mdb;Jet OLEDB:Database Password=g3n3r4l;";
And I still get the following error:
"Format of Initialization string does not conform to specification"
May I have some help on this, please?
EDIT: Tried accessing the database in the Public\Documents section of a Windows Vista PC on my network with the following connection string:
\Public\Documents\Debug\App_File\ggbase.mdb;Jet OLEDB:Database Password=g3n3r4l;";
I also tried to access my own (Windows 7 PC) local Public\Documents section using the same connection string, since the serverName can be changed using the program.
Still nothing.
Try this:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\serverName\shareName\folder\myDatabase.mdb; Jet OLEDB:Database Password=g3n3r4l;Persist Security Info=False;"
You must need to test first if you can access the shared path folder on client P.C. And if it can access it there will be no problem.Make sure also that the client user is administrator so it can do CRUD using you app.
Regards
Well, I actually solved it. Wow.
It turns out, there was an extra " at the very end of the connection string from the .ini file.
//Try This One...
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
Con = new OleDbConnection(#constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;

Provider needed to be specify on a connectionstring?

I have a very funny problem on my application, I get an error as follow:
System.ArgumentException: An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.
However, when I tried to speicify the provider on my connection as Provider=SQLOLEDB.1 or Provider=SQLOLEDB, then I get another error saying invalid keyword 'Provider'.
But one thing I noticed, the computer that I am targeting to had 2 different database system, will that cause this error?
Any idea how to solve this problem?
Regards
Assuming that you are using ADO.NET, if you want to use distinct database systems, then you need to correct the DbConnection too, not only the connection string.
Note that you can't use an SqlConnection for OLEDB, you need to use System.Data.OleDb.OleDbConnection instead.
Looks like your missing some bits of the connection string - try these
General Connection String:
strConnect = _T("Provider=sqloledb;Data Source=MyServerName;"
"Initial Catalog=MyDatabaseName;"
"User Id=MyUsername;Password=MyPassword;");
Named Instance Connection String:
strConnect = _T("Provider=sqloledb;Data Source=MyServerName\MyInstanceName;"
"Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");
Trusted Security:
strConnect = _T("Provider=sqloledb;Data Source=MyServerName;"
"Initial Catalog=MyDatabaseName;"
"Integrated Security=SSPI;");
From here http://www.codeproject.com/KB/database/connectionstrings.aspx#OLE DB SqlServer

Categories

Resources