无法在MS visual Studio 2010中执行ConnectionString

无法在MS visual Studio 2010中执行ConnectionString

问题描述:

在过去的一周中,我一直坚持这样做,如果你们能提供帮助,我将感到非常高兴。

I've been stuck with this for the past week and would be very glad if you guys could help.

我正在与MS Visual Studio合作开发vb 2010。我目前在asp.net文件夹下有一个名为 app_data的数据库。

I'm working on vb with MS visual studio 2010. I currently have a database under a asp.net folder named "app_data".

我正在尝试通过web.config文件执行connectionString命令。

I'm trying to execute a connectionString command via web.config file.

Web Config:

Web Config:

<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行突出显示):

I'm getting the following error(line 10 is being highlighted):

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

如果您能提供帮助,我们将非常高兴。

Would be glad if you guys can help.

user2072778,请尝试此操作,它可能会起作用:

user2072778, try this one, it might work:

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

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

And this is a good page for searching this theme: http://www.connectionstrings.com/sql-server-2008