04. juni 2010 - 20:00Der er
12 kommentarer og 1 løsning
Opret connectionstring til SQL2005 i vb.net?
Hej! Jeg har problem med at oprette forbindelse til sql server 2005 i vb.net, til brug på en webside, og ønsker bare at se en standardløsning på hvordan den kan opbygges!
Jeg har forsøgt at bruge noget fra et svar her på sitet, men løber ind i fejlmeddelser som: "ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)."
Jeg mangler forståelse for hvad jeg skal sætte i programmeringen i starten, dvs. hvad skal inkluderes osv. Jeg har opfattet at man arbejder med en aspx side og aspx.vb side til koden. Jeg mangler bare at komme videre!
Kodeeksempel: Imports System.Data.OleDb Public MyCon As OleDbConnection
Try 'Data Source=WIN-8YDYI87C83F;Initial Catalog=EIS30Remote;User ID=sa;Password=Halden;Packet Size=512 MyCon = New OleDbConnection("provider=SqlOleDB; SERVER=WIN-8YDYI87C83F; UID=sa; PWD=Halden; DATABASE=EIS30Local") If MyCon.State = ConnectionState.Closed Then MyCon.Open() End If Catch e As Exception MsgBox("Connection to server failed.. No response", MsgBoxStyle.Critical) Err.Clear() End End Try
Dim DbRead As OleDbDataReader Dim DbCmd As OleDbCommand Try DbCmd = New OleDbCommand("Select * From Dintabel", MyCon) DbRead = DbCmd.ExecuteReader While DbRead.Read Dim Data1 As String = CStr(DbRead.Item("FeltNavn")) loop Catch ex As Exception Err.Clear() End Try
Hej! Ingen grund til at vente Arne. Har lavet rigeligt af "Hello World". Det er bare meget lang tid siden jeg har programmeret, og værktøjet ser noget anderledes ud. har travet igennem dele af nettet for netop at finde tutorials, men ikke fundet noget brugbart.
Så hvis du nu poster en helloworld.aspx og helloworld.aspx.vb hvor den sidste i sætter i label i den første, så ændrer vi den kode til at sætte labelen til noget fra databasen.
Jeg har strikket følgende sammen, det virker fint når jeg kører det via debug i visual studio, men giver fejl i web.config filen, når jeg kører den direkte i browseren via IIS?
"It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS." "Line 76: ASP.NET to identify an incoming user. Line 77: --> Line 78: <authentication mode="Windows"/> Line 79: <!-- Line 80: The <customErrors> section enables configuration"
Her er web.config filen! <?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> <appSettings/> <connectionStrings/> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development.
Visual Basic options: Set strict="true" to disallow all data type conversions where data loss can occur. Set explicit="true" to force declaration of all variables. --> <compilation debug="true" strict="false" explicit="true"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> </assemblies> </compilation> <pages> <namespaces> <clear/> <add namespace="System"/> <add namespace="System.Collections"/> <add namespace="System.Collections.Generic"/> <add namespace="System.Collections.Specialized"/> <add namespace="System.Configuration"/> <add namespace="System.Text"/> <add namespace="System.Text.RegularExpressions"/> <add namespace="System.Linq"/> <add namespace="System.Xml.Linq"/> <add namespace="System.Web"/> <add namespace="System.Web.Caching"/> <add namespace="System.Web.SessionState"/> <add namespace="System.Web.Security"/> <add namespace="System.Web.Profile"/> <add namespace="System.Web.UI"/> <add namespace="System.Web.UI.WebControls"/> <add namespace="System.Web.UI.WebControls.WebParts"/> <add namespace="System.Web.UI.HtmlControls"/> </namespaces> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </controls> </pages> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows"/> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace.
Sub Click(ByVal s As Object, ByVal e As EventArgs) Label1.Text = "Hello World" End Sub
erstattes med f.eks.:
Sub Click(ByVal s As Object, ByVal e As EventArgs) Dim con As OleDbConnection = New OleDbConnection("provider=SqlOleDB; SERVER=WIN-8YDYI87C83F; UID=sa; PWD=Halden; DATABASE=EIS30Local") con.Open Dim cmd As OleDbCommand = New OleDbCommand("Select Count(*) From Dintabel", con) Dim n As Integer = cmd.ExecuteScalar Label1.Text = "Tabellen indeholde " & n & " rækker" End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.