all groups > vj# > may 2005 >
You're in the

vj#

group:

Newbie - connecting to a mssql datasource.



Newbie - connecting to a mssql datasource. Protoculture
5/5/2005 11:01:02 AM
vj#: Please excuse my newness to this technology.

I am wondering if someone could point me in the right direction for
connecting to a mssql datasource. In Visual Studio.net I see the sql adapter,
RE: Newbie - connecting to a mssql datasource. Proto
5/6/2005 1:04:05 AM
I'm going to attempt to answer my own question.

In a desktop application ( or any application for that matter ) should I be
Re: Newbie - connecting to a mssql datasource. Lars-Inge Tønnessen [VJ# MVP]
5/8/2005 12:00:00 AM
This is a very large question. You can connect to a MS SQL server by using a
native datasource like this:


// The connection string, using Windows Authentication
System.Data.SqlClient.SqlConnection _con =
new System.Data.SqlClient.SqlConnection( "Data
Source=(local)\\MINDB;Initial Catalog=BMWCCN;Integrated Security=SSPI;" );

// Create a command for the SQL sentence.
System.Data.SqlClient.SqlCommand _cmd = _con.CreateCommand();

// Write the SQL sentence.
_cmd.set_CommandText( "SELECT * FROM Forum Where Toppnode = 1" );

// Make an dataAdapter for the sql command.
System.Data.SqlClient.SqlDataAdapter _dataAdapter = new
System.Data.SqlClient.SqlDataAdapter( _cmd );

// The result table.
System.Data.DataTable _dataTable = new System.Data.DataTable();

// Fill the result into the result table
_dataAdapter.Fill( _dataTable );

// Show the result to the user, using a DataGrid GUI component.
this.dataGrid1.set_DataSource( _dataTable );


We have two ways of connection to a SQL server, Windows authentication
(trusted connection) and SQL authentication. You can find the connection
strings on this web page: Please use Windows authentication for more
security. SQL authentication will send the login and password in plain text
over the network and can be sniffed by network packet sniffers.

http://www.connectionstrings.com/


Regards,
Lars-Inge Tønnessen

Re: Newbie - connecting to a mssql datasource. Lars-Inge Tønnessen [VJ# MVP]
5/8/2005 12:00:00 AM

It depends on the load on your database.

Please don't use the main thread for time consuming queries. Use an
asynchronious pattern.


Regards,
Lars-Inge Tønnessen

Re: Newbie - connecting to a mssql datasource. Protoculture
5/9/2005 2:09:01 AM
Hi Lars, thanks for your very helpful posting.

I've created a class to handle all my database I/O. How can I return a
recordset ( or recordset object ) from the DB class methods to the calling
Re: Newbie - connecting to a mssql datasource. Lars-Inge Tønnessen [VJ# MVP]
5/11/2005 12:00:00 AM

Fill the result into a System.Data.DataTable and return that.
See my previous post for an example.

Do you have any code you want us to take a look at, or comment?
To be able to give you a good answer, we have to see your code.


Regards,
Lars-Inge Tønnessen

AddThis Social Bookmark Button