本文介绍了如何拆分连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用C#,实体数据模型(.edmx)在ASP.Net MVC3上做一个项目,我想分割连接字符串,如 数据源= xxx- PC; 初始目录= xxx; 用户ID = sa; 密码= xxxx; 但是我无法做到这一点。 这是我在web.config中的连接字符串 < connectionStrings > < ; add name = VidyaDaanEntities connectionString = metadata = res://*/VidyaDaanEntities.csdl | res: //*/VidyaDaanEntities.ssdl|res://*/VidyaDaanEntities.msl;provider=System.Data.SqlClient;provider connection string = 数据 来源 = xxx-PC;初始 目录 = xxx;用户 ID = sa;密码= xxxx; MultipleActiveResultSets = True providerName = System.Data.EntityClient / > < / connectionStrings > 解决方案 嗨harshal 你可以得到这个子代码的连接字符串: string strConnectionString = ConfigurationManager.AppSettings [ConnectionString]; ConnectionString是连接字符串形式的名称 web.config 之后你可以用 strConnectionString.Split() strConnectionString $ p>方法。 如果您想获得有关连接字符串的更多信息,请查看以下链接: 如何从c#中的App.Config获取连接字符串 [ ^ ] 祝你好运 祝你好运。 使用System.Configuration命名空间来访问连接字符串 string myconnection = ConfigurationManager.AppSettings [ConnectionString] 之后使用split()分割连接字符串 myconnection.Split('';'')使用索引来获取数据源,初始目录等。 再次用''=''拆分以获得最终值。 i am doing a project on ASP.Net MVC3 using C#,Entity data model(.edmx),i Want to split connection string likeData Source=xxx-PC;Initial Catalog=xxx;User ID=sa;Password=xxxx;but i am unable to do that.Here is my connection string in web.config<connectionStrings> <add name="VidyaDaanEntities" connectionString="metadata=res://*/VidyaDaanEntities.csdl|res://*/VidyaDaanEntities.ssdl|res://*/VidyaDaanEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=xxx-PC;Initial Catalog=xxx;User ID=sa;Password=xxxx;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /></connectionStrings> 解决方案 Hi harshalYou can get the connection string follow of this sub code:string strConnectionString=ConfigurationManager.AppSettings["ConnectionString"];ConnectionString is the name of your connection string form web.config after that you can split the strConnectionString with strConnectionString.Split() method.If you want to the get more information about connection string please review this link:How to get Connection String from App.Config in c#[^]Good luckBest regards.Use Namespace using System.Configuration to access connectionstringstring myconnection=ConfigurationManager.AppSettings["ConnectionString"]after that use split() to split the connectionstringmyconnection.Split('';'') use index to get Data Source, Initial Catalog etc.and again split with ''=''to get final value. 这篇关于如何拆分连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 09:29