Connection to postgresql not working as expected - c#

Again I am facing a problem retrieving data from a database system - this time I'm trying to connect to Postgresql.
I installed a postgresql Server locally and created a sample database. I can connect to the server and query data via the postgres command window - so far so good.
Furthermore - after unsuccessfully trying to get a working free OleDB provider - I installed the ODBC Drivers for Unicode in 32 bit and 64 bit version. Using the ODBC Datasource managers (64 and 32 bit) I can create ODBC Sources - connection succeeds.
Now what does NOT work: according to connectionstring.com, it should be possible to connect to the server with a regular connectionstring, providing servername, UID, PWD and so on. Trying to connect to the Server via Connectionstring, I receive the message Data source name not found and no default driver specified. If I define the connectionstring with the ODBC Data Source, everything works fine.
As far as I understood, this should be possible WITHOUT the need to define a ODBC Datasource for each and every database. Since the application will dynamically connect to something like 20-50 Databases, it would be great, if I could stick to the dynamic connection strings instead of the datasources.
Additional: I managed to get the connection working with npgsql, but nevertheless it would be great to use OleDB (which I gave hope up to get it running...) or ODBC with the Connectionstrings without additional manual effort for each DB.

Related

Application can't connect to copy of SQL Server database on other computer

I have created a C# application that connects to a SQL Server database which I created in SQL Server 2014 Management Studio. I need to send my app, my database, and instructions to get them working to someone for assessment.
My application connects perfectly on my computer with the connection string
Data Source=(local);Initial Catalog=ReportsDB;Integrated Security=True
However I am testing it on another computer and it will not connect with that same string.
I have installed SQL Server 2014 Express on that computer, and restored the database so it is identical to my main computer.
Any advice on how to make this work, or alternatively make it portable enough to submit?
The problem I had was that I assumed that connection strings were the same (apart from computer name) between SQLServer and SQLExpress however they are not.
My solution was rather hacky- I found the SQLExpress Connection String using VS on my second computer, replaced the computer name with the (local) keyword and then made an option in my application to switch between the default SQLExpress or SQLServer connection string so the user might change it manually. I also included an option to allow them to completely modify the connection string if neither default works. This is far from the most elegant solution, but with my limited understanding, it is passable to get the system working on a new computer.

C# Sql-server on every client

I want to build an application that needs a sql database on every machine that uses the application.
Isn't it true that Chrome and Firefox store cookies in a SQL database? I did not remember installing anything like a SQL server while installing Chrome, so my question is: does every user has to install a SQL Server if my app uses one?
The best thing for your purpose is to use database servers, which will be started with your application, like SQLite or Sql Server Compact. That means, you application host the database it self and you have access over ADO.Net. This is a very smart kind of storing local data and very easy.
Do not try to install complex database systems like mssql, sybase or mysql on every client.
For example, SQLite can be delivered with a few assemblies in your product.
This answers gives a nice overview: Lightweight SQL database which doesn't require installation
In order to store information for a client application, you can use SQL Server Compact, or some other solution, like SQLite (with a library to access it).
There are other alternatives, but these two are the most common and stable.
It's true that Firefox stores cookies in a sqlite database. However, that's not the same thing as SQL Server.
If your app needs to communicate with a database, you can a) bundle a sqlite database with it, b) require an existing database on startup (Wordpress does this; you can pass it details for a mysql database to get it to use an existing installation), or c) bundle a full database (like SQL Server Compact) with your application.

Connect to an ASP.NET SQL express db with another C# Project

I'm currently working on a project that has a front end ASP.NET website where users will submit "orders". I then need to access a specific table in this database with another C# windows form application that interacts with multiple Serial Ports. (I'm not married to this idea, so if you think it's a better idea to have one website for both functions, i'm all ears)
Anyway, this question is regarding the ability to have two connection strings (one from ASP.NET, and the other from a local program. - Both of which will be run on the same computer)
On the C# end, i have a connection string of:
"AttachDbFilename=C:\\Users\\Jordan\\Documents\\Visual Studio 2012\\WebSites\\WebSite1\\App_Data\\MyxoData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;"
With this configuration, when one project is active, the other cannot access the database.
Cannot open user default database. Login failed. Login failed for user 'CMYK-164\Jordan'.
I have a feeling this is because I am using Integrated Security=true in my connection string and "User Instance=True" specifically only allows one user on a computer to log into a DB at a time...but I can't find anything that backs up my theory...or has a way around the problem.
Any suggestions would be much appreciated!
EDIT
The connection strings are not an issue. Both applications work perfectly when the other isn't active. The issue here is establishing two concurrent connections to one database, from two different C# applications.
Building on what Rafeal's response; you need to upgrade to SQL Server Express.
SQL Server Express LocalDB is a stripped-down version with a lot of limitations; one being that it does not support concurrent connections. See the link below - the part explaining the concurrent connection limitation can be found in the last sentence of the Permissions section.
http://technet.microsoft.com/en-us/library/hh510202.aspx
You can install SQL Server Express here:
http://www.microsoft.com/en-us/server-cloud/Products/sql-server-editions/sql-server-express.aspx#fbid=xWTelsiKWFm
And in Visual Studio you can use the Database Explorer to create a Data Connection to the new database to create your tables and any stored procedures you need.
If you are not familiar with .Net and SQL Server, you can connect to the SQL Server Express database easily by using the System.Data.SqlClient namespace. Since it's designed for SQL Server products, it is supposedly more efficient than using ADO.Net or other data providers. And, at least, I have found it to be quick and easy to use. For example, since the provider is explicit, you don't need to specify a provider in the connection string, resulting in a shorter string. For more information on the connection string, see this page:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx
And you can find C# and VB examples of opening a connection at the bottom of this page:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx

Difference between driver and provider

What is the difference between driver and provider in database? Is there are any explanation will be grateful.
sample : ADO.NET driver for MySQL vs providerName="System.Data.EntityClient"
From the MSDN Forum:
Driver is a program installed on a workstation or a server; it allows programs to interact with a Database Management System (DBMS). Such as, JDBC driver provides database connectivity through the standard JDBC application program interface (APIs) available in J2EE.
A data provider is a set of libraries that is used to communicate with data source. Such as, SQL data provider for SQL, Oracle data provider for Oracle, OLE DB data provider for access, excel and MySQL. It serves as a bridge between an application and a data source and is used to retrieve data from a data source and to reconcile changes to that data back to the data source.
Source: MSDN-Forum
Provider is a connectivity with particular database like Sql Server, Oracle, but we import namespaces like using system.data.msdaora, using system.data.sqlclient.
After write connection class it takes string connection string takes 4 statements uid, pwd, database, server.
After open connection by using cn.Open method.
After executing statements.
After connection close.

SQL Server connection string

I'm guessing you get hundreds of these questions, but here goes:
So I'm trying to get a Honeywell Dolphin 6100 mobile device (CE5.0, .NET Compact Framework) to talk to an SQL Server Express 2008 database installed on the machine I'm developing on.
I am a complete newbie to SQL Server and mobile development, and am still a little green in C# (yeah I know, jumped in the deep end here, eh? :D)
So far I have:
string sConnection = #"Data Source=JEZ-LAPTOP;DataBase=EMS_Main;Integrated Security=SSPI;";
SqlConnection sqc = new SqlConnection(sConnection);
sqc.Open();
The app deploys quite happily to the 6100, but the last line bugs out with a vague "SQL Exception" error.
I have tried changing the Data Source to include instance names, slashes and dots before it etc etc (even though server is just using the default instance), to no avail.
I can connect to the database in Management Studio with no problems.
So, is the connection string at fault, or is it something I haven't done correctly in SQL Server?
Thanks in advance.
This site is awesome btw, some very knowledgable guys here.
CE 5.0 does not support integrated security. I believe the first version to support it was mobile 6.1. In any case, you cannot use SSPI with your configuration. You'll have to create a SQL Server user and use that as your connection credentials.
Another thing to try, besides using a UID/PWD to connect is to refer to the server by IP. It's possible that DNS resolution is not taking place properly on your device. Hmm, that is a whole nother issue. Is your device on the same network as the SQL Server?
And for future reference, commit this handy URL to memory: http://connectionstrings.com
EDIT
Let's see something like... if Named SQL Server instance:
#"Data Source=192.168.0.56\SERVER_NAME;DataBase=EMS_Main;User Id=joe;Password=pwd;";
if not named SQL Server instance:
#"Data Source=192.168.0.56;DataBase=EMS_Main;User Id=joe;Password=pwd;";

Categories