This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Tuesday, November 11, 2008

C# DB Connection With Beta 2

If you are using Beta 2, then try this code to connect to your SQL server.

Some words about connect string: Persist Security Info can not be omitted.Data
Source is your SQL server name, not ODBC DNS name!(if you run SQL locally, put
your cursor over the icon on system toolbar , you will see "\\XXXXX", that
XXXXX is your server name).



using System;
using System.Data.OleDb;

class OleDbTest{

public static void Main()
{

OleDbConnection? aConnection = new OleDbConnection(\"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Northwind;Data Source=masterjy\");
OleDbCommand? aCommand = new OleDbCommand(\"select * from orders\", aConnection);
try{
aConnection.Open();
OleDbDataReader? aReader = aCommand.ExecuteReader();
Console.WriteLine(\"This is the returned data from Northwind's Orders table\");
while(aReader.Read()){
Console.WriteLine(aReader.GetInt32(0).ToString());
}
aReader.Close();
aConnection.Close();
}
catch(OleDbException e)
{
Console.WriteLine(\"Error: {0}\", e.Errors0.Message);
}
}
}

0 comments:

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Blog Archive

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger