2013-02-14 67 views
0

过去一周我一直坚持这一点,如果你们能够提供帮助,我将非常高兴。无法在MS Visual Studio 2010中执行ConnectionString

我正在与MS视觉工作室2010 vb工作。我目前有一个名为“app_data”的asp.net文件夹下的数据库。

我想通过web.config文件执行connectionString命令。

Web配置:

<connectionStrings> 
    <add name="mysqlcon" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\public.mdf;Integrated Security=True;User Instance=True" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 

主要代码:

Dim a As String = ConfigurationManager.ConnectionStrings("mysqlcon").ConnectionString 
     Dim conn As New MySqlConnection(a) 



     Try 


      conn.Open() 
      MsgBox("good") 

      conn.Close() 
     Catch ex As MySqlException 
      MsgBox(ex.Message) 
     Finally 
      conn.Dispose() 

     End Try 

,我发现了以下错误(10号线被聚焦):

Server Error in '/MP' Application. 

Keyword not supported. 

Parameter name: attachdbfilename 


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.ArgumentException: Keyword not supported. 
Parameter name: attachdbfilename 

Source Error: 


Line 8:  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
Line 9:   Dim a As String = ConfigurationManager.ConnectionStrings("mysqlcon").ConnectionString 
Line 10:   Dim conn As New MySqlConnection(a) 
Line 11: 
Line 12: 



Stack Trace: 


[ArgumentException: Keyword not supported. 
Parameter name: attachdbfilename] 
    MySql.Data.MySqlClient.MySqlConnectionStringBuilder.ValidateKeyword(String keyword) +108 
    MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_Item(String keyword, Object value) +18 
    System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) +185 
    MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value) +289 
    MySql.Data.MySqlClient.MySqlConnection..ctor(String connectionString) +26 
    test.Button1_Click(Object sender, EventArgs e) in C:\Users\God\Desktop\VB\MP\test.aspx.vb:10 
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563 

会很高兴,如果你们可以帮忙。

回答

2

user2072778,试试这个,它可能工作:

<add name="mysqlcon" connectionString="Data Source=|DataDirectory|public.mdf" providerName="System.Data.SqlClient" /> 

这是搜索这个主题一个很好的页面:http://www.connectionstrings.com/sql-server-2008

+0

嗨Renan,谢谢。我也尝试过(我做了很多谷歌搜索,使我在你提供的链接上登陆)。代码将返回错误“无法连接到任何指定的mysql主机” – Wilson 2013-02-14 23:23:21

+0

Wilson,是您的数据库mySql?如果是,请尝试以下操作: Server = yourServerAddress; Database = yourDataBase; Uid = yourUsername; Pwd = yourPassword; 而且我会建议你改变你的数据库名称。使用少一些通用的。 – 2013-02-15 11:34:35

1

您尝试使用MySQL的连接对象连接:

暗淡康恩作为新的MySqlConnection的(a)

的Microsoft SQL Server连接字符串:

<add name="mysqlcon" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\public.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> 

他们只是不匹配。 如果要连接到MySQL数据库,请相应地更改连接字符串。