如何在App.config中为Windows应用程序创建连接字符串 [英] how to create connection string in App.config for windows applications

查看:72
本文介绍了如何在App.config中为Windows应用程序创建连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Windows应用程序中获取数据的连接字符串。我正在获取数据,但当我在另一个系统中使用此应用程序时收到错误



string opera = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+ @\\ \\Opera Software \opera stable \History;



SQLiteConnection con = new SQLiteConnection(DataSource =+ opera +; version = 3; new = false ; compress = true;

解决方案

您需要将下面的dll复制到部署它的exe文件夹中。这些dll必须在您的本地环境中使用。

System.Data.SQLite.Linq.dll

System.Data.SQLite.DLL


请阅读我对该问题的评论。



这是一个想法:连接字符串和配置文件 [ ^ ]

嗨....

将以下文本添加到windows应用程序中的app.config



< ;配置>

< connectionstrings>

< add>

name =sqlConconnectionString =数据源=您的Sql Server名称;初始目录=您的数据库名称;用户ID =您的SQL用户ID ;密码=您的SQL密码/>









下面的代码添加到CS页面

System.Configuration.AppSettingsReader settingsReader =新System.Configuration.AppSettingsReader();

串sConnectionString =(字符串)settingsReader.GetValue(sqlCon ,typeof(string));



现在你将获得sConnectionString变量中的连接字符串....



by

anantH.g


this is the connection string to get data in the windows application. am getting the data but when i use this application in the another system getting the error

string opera = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\opera stable\History";

SQLiteConnection con = new SQLiteConnection("DataSource=" + opera + "; version=3; new =false;compress=true;"

解决方案

You need to copy below dll into the exe folder where it is deployed. These dlls you must be having in your local environment.
System.Data.SQLite.Linq.dll
System.Data.SQLite.DLL


Please, read my comment to the question.

Here is an idea: Connection Strings and Configuration Files[^]


Hi....
add this below text to app.config in windows application

<configuration>
<connectionstrings>
<add>
name="sqlCon" connectionString="Data Source=Your Sql Server Name;Initial Catalog=Your DataBase Name;User ID=Your SQL user ID;Password=Your SQL Password" />




add below code to cs page
System.Configuration.AppSettingsReader settingsReader = new System.Configuration.AppSettingsReader();
string sConnectionString = (string)settingsReader.GetValue("sqlCon", typeof(string));

now u will get the connectionstring in sConnectionString variable ....

by
anantH.g


这篇关于如何在App.config中为Windows应用程序创建连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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