pretty simple question.
I cannot connect using this string:
SqlConnection myConnection = new SqlConnection("network address=(192.168.1.120); password=userpassword; user id=username; database=myDB");
I try to change it to data source, address, anything and anytime I have a period in the string it raises an exception. If I change it to point to my localhost name with no period or a hostname that is not using an FDNQ it works just fine. does anyone know what's up with that?
The exception raised when using an IP address or server name with several subdomains is that the period is invalid. "Incorrect syntax near '.'."
I went to connectionstrings.com and copied the same string I used before and it failed.
my SQLCommand had bad SQL syntax in it due to several lines of concatenation. Stupid me.
Try it like this:
SqlConnection myConnection = new SqlConnection("network address=192.168.1.120; password=userpassword; user id=username; database=myDB");
You can find the comprehensive Keyword reference for SqlConnection connection strings here: http://msdn.microsoft.com/en-us/library/ms130822.aspx
Related
I've changed my driver for connection to Oracle and got error
Connection string is not well-formed
I had unofficial Oracle driver dotNetCore.Data.OracleClient Version=1.0.0
Now I use Oracle.ManagedDataAccess.Core Version=2.18.3
My connection string looks like there
Data Source = ORACLE.HOSTS:1521/pdb_prod;PERSIST SECURITY INFO=True;USER ID=xxxx; Password=xxxx;Pooling=false;
And it works well before
Whats wrong with my connection string?
Don't put space between equalities Data Source = ...
Data Source=ORACLE.HOSTS:1521/pdb_prod;PERSIST SECURITY INFO=True;USER ID=xxxx; Password=xxxx;Pooling=false;
you can also try
Data Source=//host:[port]/[service_name]
Btw, I dont have experience with Pooling=true you may try without it and if it succeeds you can add it
Problem detected - the connection string is read from ENV, and at the end of the connection string there was a newline character.
My admins are the best, but even they sometimes make mistakes
I tried to create SqlConnection object with connection string such as
SqlConnection con = new SqlConnection("Connection string");
However, when the program runs, exception happens, and the exception says
the keyword, port, is not supported.
So I change connection string from
server=server name;user id= user name;password=myPassword;persistsecurityinfo=False;database=Database name;Port=port number
to
server=server_name, portNum;user id= user_name;password=myPassword;persistsecurityinfo=False;database=Database_name;
or to
server=server_name: portNum;user id= user_name;password=myPassword;persistsecurityinfo=False;database=Database_name;
But I still have problems to connect to database.
Could anyone give me how to connect database with port number?
Sincerely,
You can use the port at the end of the data source
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Check http://www.connectionstrings.com/sql-server/
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;"
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;
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