posts - 50, comments - 154, trackbacks - 169

My Links

News

Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

Friends Blog

Connection String C# - VB.NET

Using C#:

using System.Data.SqlClient;
...
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString = "Data Source=(local);" +
                            "Initial Catalog=mySQLServerDBName;" +
                            "Integrated Security=SSPI";
oSQLConn.Open();

Using VB.NET:

Imports System.Data.SqlClient
...
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Data Source=(local);" & _
                            "Initial Catalog=mySQLServerDBName;" & _
                            "Integrated Security=SSPI"
oSQLConn.Open()

If connection to a remote server (via IP address):

oSQLConn.ConnectionString = "Network Library=DBMSSOCN;" & _
                            "Data Source=xxx.xxx.xxx.xxx,1433;" & _
                            "Initial Catalog=mySQLServerDBName;" & _
                            "User ID=myUsername;" & _
                            "Password=myPassword"
Where:
- "Network Library=DBMSSOCN" tells SqlConnection to use TCP/IP Q238949
- xxx.xxx.xxx.xxx is an IP address. 
- 1433 is the default port number for SQL Server.  Q269882 and Q287932
- You can also add "Encrypt=yes" for encryption

 OLE DB .NET Data Provider (System.Data.OleDb)
The OLE DB .NET Data Provider uses native OLE DB through COM interop to enable data access. 

To use the OLE DB .NET Data Provider, you must also use an OLE DB provider (e.g.  SQLOLEDB, MSDAORA, or Microsoft.JET.OLEDB.4.0).

For IBM AS/400 OLE DB Provider

' VB.NET
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String = _
           "Provider=IBMDA400.DataSource.1;" & _
           "Data source=myAS400DbName;" & _
           "User Id=myUsername;" & _
           "Password=myPassword"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

For JET OLE DB Provider

' VB.NET
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String = _
         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=C:\myPath\myJet.mdb;" & _
         "User ID=Admin;" & _
         "Password="
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

For Oracle OLE DB Provider

' VB.NET
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String = _
         "Provider=OraOLEDB.Oracle;" & _
         "Data Source=MyOracleDB;" & _
         "User ID=myUsername;" & _
         "Password=myPassword"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

For SQL Server OLE DB Provider

' VB.NET
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String = _
         "Provider=sqloledb;" & _
         "Data Source=myServerName;" & _
         "Initial Catalog=myDatabaseName;" & _
         "User Id=myUsername;" & _
         "Password=myPassword"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

For Sybase ASE OLE DB Provider

' VB.NET
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String = _
         "Provider=Sybase ASE OLE DB Provider;" & _
         "Data Source=MyDataSourceName;" & _
         "Server Name=MyServerName;" & _
         "Database=MyDatabaseName;" & _
         "User ID=myUsername;" & _
         "Password=myPassword"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
For more information, see:  System.Data.OleDb Namespace and .NET Data Providers

 ODBC .NET Data Provider (System.Data.ODBC)
The ODBC .NET Data Provider is an add-on component to the .NET 1.0 Framework SDK. It provides access to native ODBC drivers the same way the OLE DB .NET Data Provider provides access to native OLE DB providers.

For SQL Server ODBC Driver

' VB.NET
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String = _
          "Driver={SQL Server};" & _
          "Server=MySQLServerName;" & _
          "Database=MyDatabaseName;" & _
          "Uid=MyUsername;" & _
          "Pwd=MyPassword"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()

For Oracle ODBC Driver

' VB.NET
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String = _
         "Driver={Microsoft ODBC for Oracle};" & _
         "Server=OracleServer.world;" & _
         "Uid=myUsername;" & _
         "Pwd=myPassword"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()

For Access (JET) ODBC Driver

' VB.NET
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String = _
         "Driver={Microsoft Access Driver (*.mdb)};" & _
         "Dbq=c:\somepath\mydb.mdb;" & _
         "Uid=Admin;" & _
         "Pwd="
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()

For Sybase System 11 ODBC Driver

// C#
string myConnStr = "Driver={Sybase System 11};" +
                   "SRVR=mySybaseServerName;" +
                   "DB=myDatabaseName;" +
                   "UID=myUsername;" +
                   "PWD=myPassword";
OdbcConnection myConnection = new OdbcConnection(myConnStr);
myConnection.Open();

For all other ODBC Drivers

' VB.NET
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String = "Dsn=myDsn;" & _
                            "Uid=myUsername;" & _
                            "Pwd=myPassword"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
For more information, see:  ODBC .Net Data Provider

 .NET Framework Data Provider for Oracle (System.Data.OracleClient)
The .NET Framework Data Provider for Oracle is an add-on component to the .NET Framework that provides access to an Oracle database using the Oracle Call Interface (OCI) as provided by Oracle Client software. 

Using C#:

using System.Data.OracleClient;
 
OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString = "Data Source=Oracle8i;" +
                               "Integrated Security=SSPI";
oOracleConn.Open();

Using VB.NET:

Imports System.Data.OracleClient

Dim oOracleConn As OracleConnection = New OracleConnection()
oOracleConn.ConnectionString = "Data Source=Oracle8i;" & _
                               "Integrated Security=SSPI";
oOracleConn.Open()
Note: You must have the Oracle 8i Release 3 (8.1.7) Client or later installed in order for this provider to work correctly.

Note: You must have the RTM version of the .NET Framework installed in order for this provider to work correctly.

Note: There are known Oracle 7.3, Oracle 8.0, and Oracle9i client and server problems in this beta release. The server-side issues should be resolved in the final release of the product.  However, Oracle 7.3 client will not be supported.

 MySQL .NET Native Provider
The MySQL .NET Native Provider is an add-on component to the .NET Framework that allows you to access the MySQL database through the native protocol, without going through OLE DB.

Using C#

using EID.MySqlClient;
 
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "Data Source=localhost;" +
                              "Database=mySQLDatabase;" +
                              "User ID=myUsername;" +
                              "Password=myPassword;" +
                              "Command Logging=false";
oMySqlConn.Open();

Using VB.NET

Imports EID.MySqlClient

Dim oMySqlConn As MySqlConnection = New MySqlConnection()
oMySqlConn.ConnectionString = "Data Source=localhost;"  & _
                              "Database=mySQLDatabase;"  & _
                              "User ID=myUsername;"  & _
                              "Password=myPassword;"  & _
                              "Command Logging=false"
oMySqlConn.Open()

Source: http://www.able-consulting.com/dotnet/adonet/Data_Providers.htm#ODBCManagedProvider

-------------------Done here--------------------

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Tuesday, February 03, 2004 7:17 AM | Filed Under [ C# ]

Feedback

Gravatar

# re: Connection String C# - VB.NET

this is how you address a generic ODBC connection for system- or user defined named datasources:

const string dsn="dsn=mydsn";
OdbcConnection conn = new OdbcConnection(dsn);
4/6/2004 2:39 PM | Guido
Gravatar

# re: Connection String C# - VB.NET

hi!
Can i connect to a remote Oracle server, using TCP. I dont have a TNS entry for this oracle sever.
4/26/2004 8:54 AM | Raj
Gravatar

# re: Connection String C# - VB.NET

Can you be more specific, Are you trying to connect from any programming language OR, Are you trying to connect from oracle client.

4/26/2004 9:53 AM | brcraju
Gravatar

# Connection Stringre: Connection String C# - VB.NET

Hi everybody
Anybody could plz tell me how to connect MySql using C# with the help of IP Address...i tried but it gives error.
i m using .NET 2002 with MySQL & ByteFX Data Provider.
Thanx
9/4/2004 3:23 PM | Seemu
Gravatar

# re: Connection String C# - VB.NET

tnx for helping me
1/11/2005 7:05 AM | jeana
Gravatar

# re: Connection String C# - VB.NET

I'm trying to use ByteFX as a data provider in C#. I have it installed along with MySQL 4.1 and VS.NET2003. But it doesn't recognize the namespace : using ByteFX.Data.MySqlClient ????
Any suggestions would be greatly appreciated!
1/17/2005 11:19 PM | Dave
Gravatar

# re: Connection String C# - VB.NET

This is exactly what I needed...

Thank you.

Paul amand
2/9/2005 1:12 AM | Paul Amand
Gravatar

# re: Connection String C# - VB.NET

spent a day looking for this type of information. Excellent - thanks
2/14/2005 8:35 PM | Happy Geek
Gravatar

# re: Connection String C# - VB.NET

How make a program in C# which connect any URL(like www.google.com) means when user click on button(including textbox enter(www.google.com)it open the site.
2/18/2005 12:46 AM | Prakash
Gravatar

# re: Connection String C# - VB.NET

How can we do connection to tandem server remotely to nonstop sqlmx? thank you.
2/19/2005 3:23 AM | Selami ozlu
Gravatar

# re: Connection String C# - VB.NET

how i connect SQL server through DSN in .net
3/3/2005 3:47 PM | sushil
Gravatar

# re: Connection String C# - VB.NET

i have connected to oracle using VC# but i am unable to use the connection in my form.
3/9/2005 9:20 AM | subbu
Gravatar

# re: Connection String C# - VB.NET

I want to make the conection to oracle from C#, but I received the message: test connection failed because of an error in initializing provider. ORA- 00439: feature not enable:

Can someone help me?
Thank you...
3/28/2005 12:57 PM | Adi
Gravatar

# re: Connection String C# - VB.NET

i wana to connect access database using vb.net
4/27/2005 10:05 PM | hayat ali
Gravatar

# re: Connection String C# - VB.NET

This is exactly what I needed...

Thank you.
5/3/2005 3:49 PM | kosala
Gravatar

# re: Connection String C# - VB.NET

Nice document
5/12/2005 12:22 PM | Shiju S Daniel
Gravatar

# re: Connection String C# - VB.NET

Nice Document
5/12/2005 12:27 PM | Shiju S Daniel
Gravatar

# ora-01002 in oracle 7.3.4

Yo estoy conectandome desde una aplicación .Net con C# a una base de datos Oracle 7.4.3 mediante el oledb provider que viene dentro del oracle Data provider for .Net 9.2...,

string conecction = Provider=oraoledb.oracle; usr id =xx; password=yy; datasource=zz; oledb.net=true;"

oledbconnection con= new oledbconnection()
con = conecction

oledbadapter command = new oledbAdapter
command = new oledbadapter("select * from producto", con)
command.fill(dataset)
......

esto es parte de la coneccion pero tengo el error ora-01002 fetch out of sequence

Por favor si alguien ha tenidoo un problema simular su ayuda.

Gracias.
Mary


5/15/2005 6:09 AM | Mary
Gravatar

# show image on picture box


hi all
this is kiran

i want code for

show image on picture box using openfiledialog on click button
5/19/2005 12:20 PM | kiran
Gravatar

# re: Connection String C# - VB.NET

Thanks Here after there is no need for me to search for connection string 4 each provider
5/23/2005 4:47 PM | Satisa
Gravatar

# re: Connection String C# - VB.NET

"For Sybase System 11 ODBC Driver “ help a lot !!!
6/7/2005 6:54 PM | foon
Gravatar

# Vb.net with access using dsn

Hello,

I want connect access database with vb.net using dsn please send me code for it.
7/8/2005 12:22 PM | Hiren
Gravatar

# re: Connection String C# - VB.NET

Will u pls let me know that is it possible to make connection using DSN and sqlclient
7/15/2005 6:59 AM | Abha
Gravatar

# re: Connection String C# - VB.NET

Check out connectionstrings.com

It's an excellent resource!
7/18/2005 3:11 PM | Mikhail Esteves
Gravatar

# re: Connection String C# - VB.NET

Hii,

I am not able to connect sybase from C#. I am getting the following error msg

ERROR[08001][INTERSOLV][ODBC SQL Server driver][SQL server]ct_connect():directory service layer:internal directory contrl layer: Requested server name not found

I am able to connect to sybase yusing dsedit and Sybase sql advantage.

I am using the following code:

connectionString_ = "Driver={Sybase System 11};"
+ "SRVR=" + dbc.dbServerName + ";"
+ "DB=" + dbc.dbName + ";"
+ "UID=" + dbc.dbLoginName + ";"
+ "PWD=" + dbc.dbPassword ;

OdbcConnection myConnection = new OdbcConnection(connectionString_);
myConnection.Open();
myConnection.Close();

Here SRVR=au1542s.unix.xxx,4100
I am able to ping as well using au1542s.unix.xxx

Any help is gr8ly appreciated
Gravatar

# re: Connection String C# - VB.NET

Reg. Connection- i need to encrypt the oracle password sent. how can i do
8/23/2005 11:20 AM | Gayathri
Gravatar

# re: Connection String C# - VB.NET

Hi Ya,

How do you connect to a Access dB which uses a security file ?
9/8/2005 11:48 AM | Ben
Gravatar

# re: Connection String with DSN C# - VB.NET

I want to know whether i can use DSN to establish a connection in VB.NET.
If so then send code example to my ID.
Thanks
DELLSYS SOFTTECH PVT. LTD.
11/22/2005 2:05 PM | Alok Kumar Behera
Gravatar

# re: Connection String C# - VB.NET

The given example to connect oracle thru vb.net is not working. can any body help me out.
12/10/2005 7:55 AM | Anil Kulkarni
Gravatar

# re: Connection String C# - VB.NET

Can someone tell me the conn string format for Wincc DB in Vb.Net?
its urgent
12/29/2005 11:57 AM | addi
Gravatar

# re: Connection String Oracle - VB.NET

Please send us connectivity code for VB.Net & Oracle
1/16/2006 1:42 PM | Gunja
Gravatar

# re: Connection String C# - VB.NET

How to write connection string using DSN and Sqlclient. I want to store it in web.config. Reply.
1/31/2006 9:54 AM | Rakesh
Gravatar

# Connection String C#

Hi,

can u tell me how we connect the oracle database in C#.NEt and I need how we can pass the connection string and command and one more question is how we can create a datagrid inside a datagrid and how we can add check boxes or radio buttons to each data grid items(i.e rows)

please mail me to 'gopinadh2004@yahoo.com'....the answer.
2/23/2006 2:50 PM | gOPINADH
Gravatar

# re: Connection String C# - VB.NET

this is nice way for me
3/11/2006 1:37 PM | Umesh
Gravatar

# re: Connection String C# - VB.NET

Connecting oracle database in .Net may encounter a lot of errors, use the same platform by exporting your database to .Net directly.
4/16/2006 3:42 PM | Mag
Gravatar

# re: Connection String C# - VB.NET

This is great. How about ADO connecting string in C#? Please help.

Mark
5/6/2006 5:43 PM | Mark Ma
Gravatar

# re: Connection String C# - VB.NET

thank u very much for this collection
9/27/2006 3:26 PM | viin
Gravatar

# re: Connection String C# - VB.NET

Anybody have an example of a functional connection string using SQLNCLI and the failover partner attribute?

Thanks in advance.

LBonilla@youbet.com
11/7/2006 2:13 AM | Luis Bonilla
Gravatar

# re: Connection String C# - VB.NET

http://www.coolmarket.net/katalog/kat/nieruchomosci-budownictwo-0.html
3/17/2007 11:19 PM | Odionis
Gravatar

# re: Connection String C# - VB.NET

hi i want to access database through DSN name in C#
i want the connection string for that.
can u pls reply fast my project dealine is on hand
4/3/2007 3:20 PM | paul mathew
Gravatar

# provide me simple vb.net connect with sql 2000

dear all
can any tell me how can i connect My Sql server 2000 database by using dsn i.e "dsnABC" with visual basic .net
please help me
regards
jawad
4/26/2007 5:45 AM | syed muhammad jawad
Gravatar

# re: Connection String C# - VB.NET

quiero conocer niñas lindas oara mi y para presentarle a un amigo
9/25/2007 3:36 PM | edwin
Gravatar

# re: Connection String C# - VB.NET

I have it installed along with MySQL 4.1 and VS.NET2003. But it doesn't recognize the namespace : using ByteFX.Data.MySqlClient ????
4/11/2009 2:08 AM | bedroom furniture
Gravatar

# re: Connection String C# - VB.NET

public static string strConnection = @"Data Source=(Local);
Initial Catalog=AddressBook;
User Id=sa;Password=123;Timeout=10;Trusted_Connection=True";


this connection string working Xp ok but not vista
7/2/2009 9:59 AM | Jotan
Gravatar

# re: Connection String C# - VB.NET

thank u very much, now i can correctly connect sql 2005 in vb.net 2008 and
for others : hi if u have any problem in vb.net then i think i can help 4 u
mail me ur problum then i can reply correct source code bye
7/21/2009 12:24 AM | chanaka
Gravatar

# re: Connection String C# - VB.NET

any URL(like www.google.com) means when user click on button(including textbox enter(www.google.com)it open the site.
1/16/2010 10:42 PM | handbags
Gravatar

# re: Connection String C# - VB.NET

Nicely done, I like this kind of post! Keep it on like this.
1/25/2010 6:44 AM | buenos aires real estate
Gravatar

# re: Connection String C# - VB.NET

Your using system data sql client is a great piece. I enjoyed it, and more importantly, and learned few things about this important subject matter...
10/25/2010 12:13 PM | prescription medicine online
Gravatar

# re: Connection String C# - VB.NET

in c#, can i put the connection string of vb.net on something like the web.config for asp.net...so could just call the connection name..?
12/8/2010 8:30 PM | mack
Gravatar

# Connection String VB.NET

Hi..

i use the following code to connect sql but,that is not working. Help Me..

("Data Source=.; Catalog=" + textbox1.text " + ;Integrated Security=True",con)
4/1/2011 6:54 AM | Manickam G
Gravatar

# re: Connection String C# - VB.NET

C# connectionstring - sample source code

http://csharp.net-informations.com/data-providers/csharp-oledb-connection.htm

menaval.
2/8/2012 10:52 AM | menaval
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: