This is a sqldatasource rather than mysql, but concept should be similar. Personally I just go into the properties of gridview, formview or whatever I'm using and configure the datasource to connect to the name of your web.config connection string. Then
it automatically writes the datasource lines for you in your aspx page. More on connection string creation:
http://www.connectionstrings.com/
Member
10 Points
39 Posts
web.config connection
Jul 07, 2010 04:03 PM|hemo|LINK
I am trying to access Mysql database from aspx.pages using a web config file.
My web.config connection string is:
<configuration>
<connectionStrings>
<add connectionString="server-10.xxx.x.xx;uid=xxxxx;pwd=1234;database=Mydb"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
</configuration>
I can connect to the Mydb using lengthy code on each page i.e.
Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet
Dim strSQL As String
myConnection = New MySqlConnection("Database=Mydb;Data Source=10.xxx.x.xx;UId=xxxxx;Password=1234;")
strSQL = "SELECT * FROM Diary ORDER BY diarydate ASC
If the web.config code is correct, is there a way to access the Mydb from any aspx. page simpler than my present code.
Member
250 Points
136 Posts
Re: web.config connection
Jul 07, 2010 09:22 PM|DAmanding|LINK
This is a sqldatasource rather than mysql, but concept should be similar. Personally I just go into the properties of gridview, formview or whatever I'm using and configure the datasource to connect to the name of your web.config connection string. Then it automatically writes the datasource lines for you in your aspx page. More on connection string creation: http://www.connectionstrings.com/
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringName%>" SelectCommand="blah blah"></asp:SqlDataSource>
Newbie just trying to pass on what I've recently learned myself. :)