mysql的连接字符串 [英] Connection string to mysql

查看:60
本文介绍了mysql的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我认为这是一个相当简单的问题,但是我找不到找到使它起作用的方法.

在我的项目中,配置文件上有一个连接字符串,它像这样;

Hello guys,
I think this is a fairly easy question but i couldnt find a way to make it work.

On my project I have a connection string on the config file it goes like this;

<appSettings>

    <add key ="connectionstring" value="server=204.12.119.53;User Id=devgad_user; Password=;hamT)gTpp^A; database=devgad_testing;Allow Zero Datetime=true;"/>
    </appSettings>


在我的代码行中;


In the line of my code;

connection = new MySqlConnection(connectionstring);

我在这里有一个错误; 初始化字符串的格式不符合从索引114开始的规范."
我尝试从 www.connectionstrings.com [ ^ ]

我认为我得到的第二个错误更有用.您有什么想法可以分享吗?
因此,只是尝试是否可以建立连接,所以我创建了另一个项目.我用了这条线;

I have an error here as; "Format of the initialization string does not conform to specification starting at index 114."
I tried the connection strings formats for mysql from www.connectionstrings.com[^]

I think the second error I got is more helpful. any thoughts that you may share?
So just to try if I can establish a connection I created another project. I used this line;

MySqlConnection conn = new MySqlConnection("server=xxx.xx.xxx.xx;User Id=devgad_user; Password=;hamT)gTpp^A; database=devgad_testing;Allow Zero Datetime=true;"); 



在这里,我收到了错误消息不支持关键字.
参数名称:hamt)gtpp ^ a;数据库"



Here I got an error as "Keyword not supported.
Parameter name: hamt)gtpp^a; database"

推荐答案

好,您的密码以分号开头,分号是系统使用的参数分隔符.因此,它将连接字符串解释为blah=blah; password=""; hamT)gTpp^A并且它认为最后一个(您的密码)是关键字.

我不确定是否可以将其用引号引起来,但这总是会给您带来麻烦,那么为什么不将密码更改为不以控制"字符开头的密码呢?
Well, your password starts with a semi-colon which is the parameter separator used by the system. So it is interpreting your connection string as blah=blah; password=""; hamT)gTpp^A and it thinks the last one (your password) is a keyword.

I am not sure if you can enclose it in quotes or not but it is always going to give you problems, so why not change your password to something that doesn''t begin with a ''control'' character?


您的密码字符串中包含分号.这是连接字符串的关键字/值定界符.使连接对象认为您没有提供密码,并且声明了不存在的关键字.
There is a semi-colon in your password string. This is the key word/value delimiter for connection strings. Makes the connection object think you did not supply a password and are declaring a key word that does not exist.


这篇关于mysql的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆