I'm a complete newbie on ASP.Net.
I want to get some data out of a SQLserver Database running on my system with SQL Server 2005 Express. The name of the Database is 'tempdb' and the table is called "Members". the SQLServer runs as Local System with the Windows account.
When I try to open the site, I always get the same error:
Invalid object name 'Members'
I don't know what to do anymore. I read a post, where anybody set the rights for the owner, but my database is running with the Windows account.
Here is the Code of the page so far:
<%@. Page Language="VB" Debug="True" Strict="True" %>Thanks for your help an sorry for my english.
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SQlClient" %>
<script runat="server">
Sub Page_Load (ByVal Sender As Object, _
ByVal E As EventArgs)Dim connStr As String
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;"
connStr += "database=tempdb;"
connStr += "Truster_Connection=yes"
Dim conn As New SQLConnection(connStr)
conn.Open()Dim sql As String
sql = "SELECT COUNT (*) FROM Members"
Dim cmd As New SQLCommand(sql, conn)
Dim ergebnis As String
ergebnis = cmd.ExecuteScalar().toString()
Dim t As String
t = "Die Tabelle Members hat " & _
ergebnis & " Zeilen. <br>" & _
"Das Kommando lautet: " & _
cmd.CommandText & "<br>" & _
"Der Kommandotyp ist: " & _
cmd.CommandTypeausgabe.innerHTML = t
End Sub
</script>
<html><head><title>
Demo zu SQLCommand.ExecuteScalar
</title></head>
<body>
<h3>Demo zu SQLCommand.ExecuteScalar</h3>
<p runat="server" id="ausgabe" />
</body></html>
Greets
Flash_Prince
The problem is objects in tempdb is valid for limited time so your object the Member table does not exist. Microsoft provided the tempdb for SQL Server to be used to proccess complex queries and test queries so when you create a table if you did not drop it SQL Server will drop it at some point. Try the links below to download sample databases you can create and use with SQL Server 2005. The databases comes with tables but you can create your own tables so you can add the member table to any of the three database. Hope this helps.
http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en
http://www.microsoft.com/downloads/details.aspx?FamilyID=e719ecf7-9f46-4312-af89-6ad8702e4e6e&DisplayLang=en
|||The problem is, that i want to use the database without entering the path of the database file in the sourcecode. When I use the nordwind database, all the sql queries are working very well. But if I use the Nordwind Database, I only know to connect by OleDB.
Can you tell me how to use a database in the way decribed above with a sql connection?
I hope, this is described understandable, cause my english is not the best.
|||You need to create connection string and most of the information you need is covered in the two links below. Hope this helps.
http://www.connectionstrings.com
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000010.asp
|||The problem is in your connection string. You have a typo: "Truster_Connection=yes" should be "Trusted_Connection=yes".
No comments:
Post a Comment