开发者

C#.NET connecting to host mysql database

开发者 https://www.devze.com 2023-03-28 16:53 出处:网络
I want to connect my C# .NET website using Visual Studio to a MySQL database located with the host 123-REG.

I want to connect my C# .NET website using Visual Studio to a MySQL database located with the host 123-REG.

I have put the following code snippet (edited 开发者_如何转开发for security) into my web.config file:

 < appSettings >
 < add key="ConnectionString" value="Server=XX; Database=XX; User Id=XX; Password=XX" / > 
 < /appSettings >

But now I don't know what I should put in my code to read and write to this database.

So what should my connection string look like? Also, do I need to do anything for port settings?

If anyone has already been down this path, I would really welcome your help.


Visual Studio does not have native support for MySql Database, so yo need to install MySql Connector/Net: link

After from UI you can set everything, and it will generate the connection string for you: link

[EDIT]

From http://www.connectionstrings.com/mysql

For Standard connection (Default port is 3306.)

 <connectionStrings>
    <add name="MyConnStr" connectionString="Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"/>
</connectionStrings>

If you need to specifie the port:

 <connectionStrings>
    <add name="MyConnStr" connectionString="Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"/>
</connectionStrings>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号