Thursday, 22 March 2012

Connect to ms sql server 2000

I just installed ms sql server 2000 and want to make a connection to it. How do I do that? I have created a database with the name Test and a table with the name testTabel.Lookhere for informaiton on connecting.

Lookhere for info on selecting data.|||Thx for support... am trying to connect to db like this:


<%@. Page Language="C#" Debug="true" %>
<%@. import Namespace="System.Data" %>
<%@. import Namespace="System.Data.SqlClient" %>
<script runat="server"
void Page_Load()
{
string strSql = "select FirstName,LastName from Employees";
string strConnection ="server=dbo;";
strConnection += "database=Northwind;uid=sa;password=;";
DataSet objDataSet = new DataSet();
SqlConnection objConnection = new SqlConnection(strConnection);

SqlDataAdapter objDataAdapter = new SqlDataAdapter(strSql,objConnection);

objDataAdapter.Fill(objDataSet,"Employees");

DataView objDataView = new DataView(objDataSet.Tables["Employees"]);

dgrEmployees.DataSource = objDataView;
dgrEmployees.DataBind();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="dgrEmployees" runat="server"></asp:DataGrid>
</form>
</body>
</html

but I get an exception :

SQL Server findes ikke, eller adgang blev nægtet.
Beskrivelse: Der opstod en ikke-afviklet undtagelse under udførelse af den aktuelle webanmodning. Se staksporingen for at få yderligere oplysninger om fejlen, og hvor den kom fra i koden.

Detaljer om undtagelse: System.Data.SqlClient.SqlException: SQL Server findes ikke, eller adgang blev nægtet.

Kildefejl:

Linje 14: SqlDataAdapter objDataAdapter = new SqlDataAdapter(strSql,objConnection);
Linje 15:
Linje 16: objDataAdapter.Fill(objDataSet,"Employees");
Linje 17:
Linje 18: DataView objDataView = new DataView(objDataSet.Tables["Employees"]);

Kildefil: C:\Documents and Settings\aslan1\Skrivebord\Asp.Net\test1\sql3.aspx Linje: 16

Staksporing:

[SqlException: SQL Server findes ikke, eller adgang blev nægtet.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +472
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +311
System.Data.SqlClient.SqlConnection.Open() +383
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +44
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
ASP.sql3_aspx.Page_Load() in C:\Documents and Settings\aslan1\Skrivebord\Asp.Net\test1\sql3.aspx:16
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731

can U plz tell me why I get this SqlException??|||I cannot understand the output of the exception. My guess is that it is related to security in some way. Is the sa password really blank, or had you sent a correct password in the string on the page but removed it to display here?

I think the string you are using to connect is not quite correct. Try:


string strConnection ="server=dbo;";
strConnection += "database=Northwind;user id=sa;password=;";
|||thx a lot it solved the problem...sqlsql

No comments:

Post a Comment