Ilano 0 Denunciar post Postado Julho 6, 2006 Olá pessoal, Como faço para criar uma conexão com o MySQL usando o web.config? Estou tentando fazer assim: No web.config: <appSettings> <add key ="cStrConexao" value = "Data Source =Meu_IP; Database=Minha_Base; Uses ID=root; Password=Minha_Senha;Command Logging=false"/> </appSettings> No form, está assim: Imports MySql.Data.MySqlClient Partial Class index Inherits System.Web.UI.Page Private Db As classDatabase.DbOle Private Sub PovoaModulo() Dim Conexao As MySqlConnection Dim Da As MySqlDataAdapter Dim Ds As Data.DataSet Dim StrSQL As String Conexao.ConnectionString = ConfigurationSettings.AppSettings("cStrConexao") StrSQL = "SELECT * FROM tb_modulos" Da = New MySqlDataAdapter(StrSQL, Conexao) Ds = New Data.DataSet Da.Fill(Ds) End Sub Mas não está dando certo. Vcs poderiam me ajudar? Grato, Ilano. Compartilhar este post Link para o post Compartilhar em outros sites
Tiago Colombo 0 Denunciar post Postado Julho 7, 2006 Olá,qual o erro que retorna?[]´s Compartilhar este post Link para o post Compartilhar em outros sites
Ilano 0 Denunciar post Postado Julho 7, 2006 Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 24: Dim Ds As Data.DataSet Line 25: Dim StrSQL As String Line 26: Conexao.ConnectionString = ConfigurationSettings.AppSettings("cStrConexao") Line 27: StrSQL = "SELECT * FROM tb_noticias ORDER BY Not_Data, Tema_Codigo, Not_Titulo" Source File: C:\Documents and Settings\ilano.DAP-DES01\Meus documentos\Aplicacoes Web\AG\index.aspx.vb Line: 26 Compartilhar este post Link para o post Compartilhar em outros sites
Juliano.net 2 Denunciar post Postado Julho 8, 2006 Você não instanciou um dos objetos que você está utilizando.Poste uma parte maior do seu código para que possamos analisar. Compartilhar este post Link para o post Compartilhar em outros sites
Ilano 0 Denunciar post Postado Julho 10, 2006 Juliano.net, Meu Web.config está assim: <?xml version="1.0"?> <!-- Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.Net\Framework\v2.x\Config --> <configuration> <appSettings> <add key ="cStrConexao" value = "Data Source =localhost; Database=MinhaBase; Uses ID=root; Password=MinhaSenha;Command Logging=false"/> </appSettings> <connectionStrings> </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"/> <pages> <namespaces> <clear/> <add namespace="System"/> <add namespace="System.Collections"/> <add namespace="System.Collections.Specialized"/> <add namespace="System.Configuration"/> <add namespace="System.Text"/> <add namespace="System.Text.RegularExpressions"/> <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> </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. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> </system.web> </configuration> E o meu código está assim: Imports MySql.Data.MySqlClient Partial Class index Inherits System.Web.UI.Page Private Db As classDatabase.DbOle Private Sub PovoaModulo() Dim Conexao As MySqlConnection Dim Da As MySqlDataAdapter Dim Ds As Data.DataSet Dim StrSQL As String Conexao.ConnectionString = ConfigurationSettings.AppSettings("cStrConexao") StrSQL = "SELECT * FROM tb_modulos" Da = New MySqlDataAdapter(StrSQL, Conexao) Ds = New Data.DataSet Da.Fill(Ds) End Sub Compartilhar este post Link para o post Compartilhar em outros sites