Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将数据库连接字符串存储到.net DLL数据层的my.settings中_Asp.net_Vb.net_Dll_Data Access Layer_Strongly Typed Dataset - Fatal编程技术网

Asp.net 将数据库连接字符串存储到.net DLL数据层的my.settings中

Asp.net 将数据库连接字符串存储到.net DLL数据层的my.settings中,asp.net,vb.net,dll,data-access-layer,strongly-typed-dataset,Asp.net,Vb.net,Dll,Data Access Layer,Strongly Typed Dataset,大家好 在为web应用程序实现数据层DLL时,我始终使用这种方法: 1) 将数据集放入dll项目 2) 将助手类与以下方法一起使用: public shared sub settCnnStr(strconnhere as string) My.Settings.Item("connectionString") = strconnhere end sub 3) 当我需要使用dll时,我会调用这样的方法(通常为global.asax): 这种方法对我来说总是很好,但我想知道这种方法是否有严重的缺点

大家好 在为web应用程序实现数据层DLL时,我始终使用这种方法:

1) 将数据集放入dll项目 2) 将助手类与以下方法一起使用:

public shared sub settCnnStr(strconnhere as string)
My.Settings.Item("connectionString") = strconnhere
end sub
3) 当我需要使用dll时,我会调用这样的方法(通常为global.asax):

这种方法对我来说总是很好,但我想知道这种方法是否有严重的缺点,或者是否有更好的解决方案

谢谢


Pierluigi

我认为这种方法没有任何严重的缺点

不过稍微好一点的解决方案可能是在配置文件中指定连接字符串,并通过对象直接从类库项目中读取它

如何使用My.Setting读取连接字符串设置 1) 在类库项目中的中添加连接字符串设置。这将把它添加到项目的
App.config
配置文件中,并生成一个自定义类

2) 由于类库项目无法读取
App.config
文件,因此必须将生成的连接字符串设置移动到
Web.config
文件:

<configuration>
    <connectionStrings>
        <add name="ClassLibrary.My.MySettings.MyConnString"
             connectionString="SomeConnString" />
    </connectionStrings>
</configuration>
相关资源:


这是一个很好的解决方案,但通常DLL连接字符串取决于web应用程序上的哪个用户登录。因此,我更喜欢在用户登录后以友好方式设置连接字符串。您的用户是否使用Windows帐户登录?在这种情况下,您可以使用经过身份验证的用户的身份连接到数据库。在这种情况下,连接字符串将不包含任何登录凭据,因此是静态的。
<configuration>
    <connectionStrings>
        <add name="ClassLibrary.My.MySettings.MyConnString"
             connectionString="SomeConnString" />
    </connectionStrings>
</configuration>
Dim connString = My.Settings.MyConnString