Wednesday, March 28, 2012

MS SQL sever 2000 string connection problem

Hi, i'm very new to Web Matrix. I've been following the C# end-end application tutorial exactly but i can't seem to run my application.
The code given in the link below is for MS Access but I'm using MS SQL 2000, so i'm not sure of the syntax for the code provided below (string connectionString...)
Please help..thank u!!

http://www.asp.net/webmatrix/guidedtour/section91/bookrequestcontrol.aspx

string connectionString = @."Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\TempProjects\LibraryDatabase.mdb";

public void LoadRequestedBooks(){

try

{

string mySelectQuery = string.Format("SELECT books.* from books, requests where books.bid = requests.bid and requests.mid = {0}", Session["userid"]);

System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(connectionString);

System.Data.DataSet myDataSet = new System.Data.DataSet();

System.Data.OleDb.OleDbDataAdapter myOleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter(mySelectQuery, myConnection);

myOleDbDataAdapter.Fill(myDataSet);

DataGrid1.DataSource = myDataSet.Tables[0];

DataGrid1.DataBind();

myConnection.Close();

}

catch(Exception exp)

{

Label2.Text = "<br>Error: " + exp.Message + "<br>";

}

}Hi,

You may take a look at another section of the Web Matrix tutorial,
which is primarily focus on data access with SQL/MSDE Server:
http://asp.net/webmatrix/tour/section2/newconn.aspx

Colt|||hi again. thanks for the site, but my problem is the database is not storred locally. it's on the server. How should i change the syntax in the following code to suit MS Sql Server2000? Your help will be very much appreciated. Thank you.

string connectionString = @."Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\TempProjects\LibraryDatabase.mdb";
public void LoadRequestedBooks(){

try
{

string mySelectQuery = string.Format("SELECT books.* from books, requests where books.bid = requests.bid and requests.mid = {0}", Session["userid"]);
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(connectionString);
System.Data.DataSet myDataSet = new System.Data.DataSet();
System.Data.OleDb.OleDbDataAdapter myOleDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter(mySelectQuery, myConnection);

myOleDbDataAdapter.Fill(myDataSet);
DataGrid1.DataSource = myDataSet.Tables[0];
DataGrid1.DataBind();
myConnection.Close();

}
catch(Exception exp)
{
Label2.Text = "<br>Error: " + exp.Message + "<br>";

}

}|||Hi,

I see.. You can connect to a remote DB server by using its IP address,
E.g. "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
FYI:http://www.connectionstrings.com

Colt

No comments:

Post a Comment