Connect to SQL Server

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
I am trying to connect to Microsoft SQL Server 2005 Management Studio Express with VB.NET, but i have no idea which DB component is the best for this. I tried to connect it with OLEDB and i encountered an error message like this:

Login timeout expired
An error has occured while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections
Named Pipes Provider: Could not open a connection to SQL Server [2]..

I made use of OLEDB because i am quite familiar with the coding but may i know is it a best choice? Thank you.
 
Last edited:
SQLClient is what you should be using to connect to a SQL Server. Are you trying to connect to a local Database, one on a server, or somewhere else?


-tg
 
I can connect to MY SQL with SqlConnection, may i know what is the sample coding for insert, delete, insert as well as retrieval. Thank you.
 
well if you are using VS 2005 like your profile says you are, then as soon as you add a DataSet in the wizard and create your table adapters, all of your code is generated by VS. You then can add selection queries to each table if needbe (i.e. parameter ones - @FieldName)

So your select code, i.e. SELECT * FROM TABLE, is built into your query on the TableAdapter.

On your form you then bind your textboxes / comboboxes to the dataset and use something like;

Me.TableAdapter1.Fill(DataSet1.Table1)


I'd suggest you get a beginner's book or even try searching on these forums - this question is asked many a time each day....
 
I have made use of the OLEDB to connect to SQL Server and my application currently works fine. Anyway, may i know what is the difference between each component since there are quite a number of database component in VB.NET? And how can we tell which one is the better for certain type of database since they are quite similar? Thank you.
 
Do a search for something like "SQLConnection vs OleDBConnection" on any search engine website (Google, Yahoo) and you'll get a fair few pages expaining the differences.

That took my 5 seconds and the first page came back with

OleDbConnection uses OLE DB data providers to communicate with different kinds of databases. You can make use of Data Links dialog to construct the connection string for an OleDbConnection. However, you can not use this dialog to construct connection string for other data sources. Therefore, for a SqlConnection, e.g., you have to type in the connection string yourself.
Here is a connection string for an OleDbConnection using OLE DB Provider for SQL Database:
Provider=SQLOLEDB.1; Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=Northwind; Data Source=FLIU2000\NetSDK
Here is the connection string for a SqlConnection:
Integrated Security=SSPI; initial catalog=northwind; data source=FLIU2000\NetSDK

The internet is a wealth of information.....

I always tend to use an SQLConnection if I'm connecting to an SQL server....don't see why it would be there otherwise :)
 
Back
Top