PDA

View Full Version : connection string



linux
جمعه 30 دی 1384, 21:11 عصر
در vb2005 وقتی با ویزارد به دیتا بیس وصل میشی که connection string می سازه وقتی برنامه را کامپایل می کنی اگر بخواهیم این کانکشن را دوباره مقدار دهی کنیم نمیشه چون read only هست راه حلی برای اینکار وجود داره؟

M.kavyani
جمعه 30 دی 1384, 23:06 عصر
در vb2005 وقتی با ویزارد به دیتا بیس وصل میشی که connection string می سازه وقتی برنامه را کامپایل می کنی اگر بخواهیم این کانکشن را دوباره مقدار دهی کنیم نمیشه چون read only هست راه حلی برای اینکار وجود داره؟
دوست عزیز در قسمت saolution Explorer رفته و بعد از روی آن بخش MyProject دوبار کلیک کن تا باز شود. حالا به بخش Setting برو و از آنجا Connection String مربوطه رو تغییر بده!
.

linux
جمعه 30 دی 1384, 23:16 عصر
این را که بلدم عزیز دل برادر!
منظورم این هست فرض کن برنامه را نوشتی کامپایل هم کردی دادی دست مشتری
برنامه یک login فرم داره که اونجا کاربر اسم و پسوردش را وارد مکنه حالا من می خواهم بعد از اینکه کاربر اسم و پسوردش را وارد کرد آن کانکش را دوباره مقدار دهی کنم اونوقت باید چیکار کنم.

M.kavyani
یک شنبه 16 بهمن 1384, 23:41 عصر
این را که بلدم عزیز دل برادر!
منظورم این هست فرض کن برنامه را نوشتی کامپایل هم کردی دادی دست مشتری
برنامه یک login فرم داره که اونجا کاربر اسم و پسوردش را وارد مکنه حالا من می خواهم بعد از اینکه کاربر اسم و پسوردش را وارد کرد آن کانکش را دوباره مقدار دهی کنم اونوقت باید چیکار کنم.
با سلام
دوست عزیز حق با شماست. Scope این Connection String که خود برنامه تحت ویزارد ایجا میکنه Application هست و قابل تغییر به User نیست. به عبارتی همیشه ReadOnly هست.
منم به این مشکل برخوردم. این تاپیک مال چند وقت پیشه. میخواستم بدونم مشکلت حل شد یا نه؟
اگر حل شد مارو هم درجریان بذار.
در پناه حق موفق و کامروا باشید.

Hamedm
دوشنبه 17 بهمن 1384, 00:36 صبح
برنامه یک login فرم داره که اونجا کاربر اسم و پسوردش را وارد مکنه حالا من می خواهم بعد از اینکه کاربر اسم و پسوردش را وارد کرد آن کانکش را دوباره مقدار دهی کنم اونوقت باید چیکار کنم.

سلام

مگه نوع login بانکت با login کاربر ارتباط داره؟
اگه جوابتون مثبته، میشه دلیلشو بگید؟

در پناه حق موفق باشید و پرتوان

روح اله معینی زاده
دوشنبه 17 بهمن 1384, 07:32 صبح
سلام دوست گرامی
بهتره از روش دستی استفاده کنی.
من هم همین مشکل رو داشتم. دوستان هم همین رو گفته بودند و من تا وقتی با wiz خود وی بی کار می کردم معمولاً با یه جابه جایی بانک به این مشکل بر می خوردم و مجبور بودم دوباره برنامه رو کامپایل کنم (هر چند ممکن بود که در سال یک بار باشه، اونم به علت نصب مجدد ویندوز و مسائل دیگه).

بنابراین اگه نمی تونی این پروژه رو تغییر بدی حداقل از پروژه بعدی خودت رو مجبور کن که با کدنویسی به بانک وصل شد اگه می خوای خیلی انعطاف پذیر برنامه بنویسی.

با احترام- خدانگهدار.

linux
دوشنبه 17 بهمن 1384, 14:46 عصر
سلام

مگه نوع login بانکت با login کاربر ارتباط داره؟
اگه جوابتون مثبته، میشه دلیلشو بگید؟

در پناه حق موفق باشید و پرتوان
از مدل sqlauthenicaton استفاده می کنم

linux
دوشنبه 17 بهمن 1384, 15:14 عصر
سلام دوست گرامی
بهتره از روش دستی استفاده کنی.
من هم همین مشکل رو داشتم. دوستان هم همین رو گفته بودند و من تا وقتی با wiz خود وی بی کار می کردم معمولاً با یه جابه جایی بانک به این مشکل بر می خوردم و مجبور بودم دوباره برنامه رو کامپایل کنم (هر چند ممکن بود که در سال یک بار باشه، اونم به علت نصب مجدد ویندوز و مسائل دیگه).

بنابراین اگه نمی تونی این پروژه رو تغییر بدی حداقل از پروژه بعدی خودت رو مجبور کن که با کدنویسی به بانک وصل شد اگه می خوای خیلی انعطاف پذیر برنامه بنویسی.

با احترام- خدانگهدار.
یعنی چطوری؟انوقت دیگه نمیشه از فایل های dataset استفاده کرد؟
توی msdn یک روشی را برای secure کردن گفته ولی من نتونستم پیادش کنم

sh
دوشنبه 17 بهمن 1384, 17:21 عصر
تو یه سایتی این راه حل رو نوشته بودند

I just change the Type from Connection String to String and the Scope from Application to User, and it worked.

ali_kolahdoozan
دوشنبه 17 بهمن 1384, 17:39 عصر
baba khob code benevis

linux
دوشنبه 17 بهمن 1384, 18:32 عصر
بعله که کار می کنه! ولی باز این امنیت نداره
باز میشه از تو فایل app.config به پسورد رسید.

M.kavyani
دوشنبه 17 بهمن 1384, 23:43 عصر
تو یه سایتی این راه حل رو نوشته بودند

I just change the Type from Connection String to String and the Scope from Application to User, and it worked.

با سلام
Scope این ConnetctionString که با Wizard ساخته میشه از نوع Application است.به عبارتی Readonly می باشد و جالب اینجاست که این Scope به User قابل تغییر نیست.
حداقل من یکی که هرکاری کردم نتوانستم تغییری ایجاد کنم.

M.kavyani
دوشنبه 17 بهمن 1384, 23:49 عصر
بعله که کار می کنه! ولی باز این امنیت نداره
باز میشه از تو فایل app.config به پسورد رسید.
یه نکته جالب توجهی که هست اینه که شما بعد از اینکه برنامه خود را Build کردید میتوانید این فایل را پاک کنید. و اطلاعات در فایل دیگری به نامApplicationName.settings ذخیره میشود.
موندم که این فایل App.config برای چه؟( هر چند که اطلاعات درونش ذخیره میشوند و لی عملا" کاربرد نداره:گیج: )

reham
یک شنبه 23 بهمن 1384, 10:57 صبح
نمیدونم درست فهمیدم...
مشکل شما اینه که با تغییر بانک امکان تغییر connection string توسط کاربر باشه؟؟؟؟؟
استفاده از udl کار خوبیه که اونم با ole کار میکنه.وگرنه باید یا از به فایل بخونی یا تو سورس دست ببری...

M.kavyani
یک شنبه 23 بهمن 1384, 18:33 عصر
نمیدونم درست فهمیدم...
مشکل شما اینه که با تغییر بانک امکان تغییر connection string توسط کاربر باشه؟؟؟؟؟
استفاده از udl کار خوبیه که اونم با ole کار میکنه.وگرنه باید یا از به فایل بخونی یا تو سورس دست ببری...
با سلام
میشه بیشتر توضیح بدی؟
به این نکته هم توجه داشته باش که ما از Setting موجودر در VB.NET 2005 بهره میبریم.
با تشکر
درپناه حق موفق و کاروا باشید
:تشویق:

linux
یک شنبه 23 بهمن 1384, 20:01 عصر
راستی من این را پیدا کردم ولی راستش وقت نکردم روش کار کنم


ASP.NET
How To: Secure Connection Strings When Using Data Source Controls
See Also
Language Filter: All Language Filter: Multiple Language Filter: Visual Basic Language Filter: C# Language Filter: C++ Language Filter: J# Language Filter: JScript
Visual Basic (Declaration)
Visual Basic (Usage)
C#
C++
J#
JScript

When working with data source controls it is recommended that you centralize the location of your connection strings by storing them in the application's Web.config file. This simplifies the management of connection strings by making them available to all of the ASP.NET pages in a Web application. In addition, you do not need to modify numerous individual pages if your connection string information changes. Finally, you can improve the security of sensitive information stored in a connection string, such as the database name, user name, password, and so on, by encrypting the connection string section of the Web.config file using protected configuration.

This topic describes how to store connection strings in the connectionStrings configuration section in the Web.config file, and how to use the command-line .NET Framework tool to encrypt connection strings for additional security.

To store a connection string in the Web.config file
Open the Web.config file for your application. If a Web.config file does not already exist, create a text file named Web.config and add the following content:

Copy Code
<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings/>
<system.web>
</system.web>
</configuration>


In the configuration element, create a new element named connectionStrings, as shown in the following example:

Copy Code
<?xml version="1.0"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
</connectionStrings>
<appSettings/>
<system.web>
</system.web>
</configuration>


In the connectionStrings element, create an add element for each connection string you will use in your Web application. Include the attributes shown in the following table.

Attribute Description
name
A name for this connection string configuration object. This name will be used by data source controls and other features to reference the connection string information.

connectionString
The connection string to the data source.

providerName
The namespace of the NET Framework data provider to use for this connection, such as System.Data.SqlClient, System.Data.OleDb or System.Data.Odbc.


A completed connectionStrings element might look like the following example:

Copy Code
<connectionStrings>
<add
name="NorthwindConnection"
connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;" />
</connectionStrings>


Save and close the Web.config file.

You can now reference the connection string for your data source control by referring to the name you specified for the name attribute.

In the ConnectionString attribute for your data source control, use the connection string expression syntax to reference the connection information from the Web.config file.

The following example shows a SqlDataSource control in which the connection string is read from the Web.config file:

Copy Code
<asp:SqlDataSource ID="ProductsDataSource" Runat="server"
SelectCommand="SELECT * from Products"
ConnectionString="<%$ ConnectionStrings: NorthwindConnection %>"
</asp:SqlDataSource>



To encrypt connection string information stored in the Web.config file
At the Windows command line, run the ASP.NET IIS registration tool (aspnet_regiis.exe) with the following options:

The -pe option, passing it the string "connectionStrings" to encrypt the connectionStrings element.

The -app option, passing it the name of your application.

The aspnet_regiis.exe tool is located in the %systemroot%\Microsoft.NET\Framework\versionNumber folder.

The following example shows how to encrypt the connectionStrings section of the Web.config file for an application named SampleApplication:

Copy Code
aspnet_regiis -pe "connectionStrings" -app "/SampleApplication"


When the command has finished, you can view the contents of the Web.config file. The connectionStrings configuration section will contain encrypted information instead of a clear-text connection string, as shown in the following example:

Copy Code
<configuration>
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>RSA Key
</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>WcFEbDX8VyLfAsVK8g6hZVAG1674ZFc1kWH0BoazgOwdBfinhc AmQmnIn0oHtZ5tO2EXGl+dyh10giEmO9NemH4YZk+iMIln+Itc Eay9CGWMXSen9UQLpcQHQqMJErZiPK4qPZaRWwqckLqriCl9X8 x9OE7jKIsO2Ibapwj+1Jo=
</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>OpWQgQbq2wBZEGYAeV8WF82yz6q5WNFIj3rcuQ8gT0MP97aO9S HIZWwNggSEi2Ywi4oMaHX9p0NaJXG76aoMR9L/WasAxEwzQz3fexFgFSrGPful/5txSPTAGcqUb1PEBVlB9CA71UXIGVCPTiwF7zYDu8sSHhWa0fN XqVHHdLQYy1DfhXS3cO61vW5e/KYmKOGA4mjqT0VZaXgb9tVeGBDhjPh5ZlrLMNfYSozeJ+m2Lsm 7hnF6VvFm3fFMXa6+h0JTHeCXBdmzg/vQb0u3oejSGzB4ly+V9O0T4Yxkwn9KVDW58PHOeRT2//3iZfJfWV2NZ4e6vj4Byjf81o3JVNgRjmm9hr9blVbbT3Q8/j5zJ+TElCn6zPHvnuB70iG2KPJXqAj2GBzBk6cHq+WNebOQNWI b7dTPumuZK0yW1XDZ5gkfBuqgn8hmosTE7mCvieP9rgATf6qgL gdA6zYyVV6WDjo1qbCV807lczxa3bF5KzKaVUSq5FS1SpdZKAE 6/kkr0Ps++CE=
</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
</configuration>


Leave the command prompt open for later steps.

Determine the user account or identity under which ASP.NET runs by retrieving the current WindowsIdentity name.

The following example shows one way to determine the WindowsIdentity name:

Visual Basic Copy Code
<%@ Page Language="VB" %>
<%
Response.Write(System.Security.Principal.WindowsId entity.GetCurrent().Name)
%>



C# Copy Code
<%@ Page Language="C#" %>
<%
Response.Write(System.Security.Principal.WindowsId entity.GetCurrent().Name);
%>

Note
By default, on Windows Server 2003 with impersonation for an ASP.NET application disabled in the Web.config file, the identity under which the application runs is the NETWORK SERVICE account. On other versions of Windows, ASP.NET runs under the local ASPNET account.


The user account or identity under which ASP.NET runs must have read access to the encryption key used to encrypt and decrypt sections of the Web.config file. This procedure assumes that your Web site is configured with the default RsaProtectedConfigurationProvider specified in the Machine.config file named "RsaProtectedConfigurationProvider". The RSA key container used by the default RsaProtectedConfigurationProvider is named "NetFrameworkConfigurationKey".

At the command prompt, run the aspnet_regiis.exe tool with the following options:

The -pa option, passing it the name of the RSA key container for the default RsaProtectedConfigurationProvider.

The identity of your ASP.Net application, as determined in the preceding step.

The following example shows how to grant the NETWORK SERVICE account access to the machine-level "NetFrameworkConfigurationKey" RSA key container:

Copy Code
aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AUTHORITY\NETWORK SERVICE"


To decrypt the encrypted Web.config file contents, run the aspnet_regiis.exe tool with the -pd option. The syntax is the same as encrypting Web.config file contents with the -pe option except that you do not specify a protected configuration provider. The appropriate provider is identified in the configProtectionProvider attribute for the protected section.

The following example shows how to decrypt the connectionStrings element of ASP.NET application SampleApplication.

Copy Code
aspnet_regiis -pd "connectionStrings" -app "/SampleApplication"



See Also
Other Resources
Encrypting Configuration Information Using Protected Configuration


To make a suggestion or report a bug about Help or another feature of this product, go to the feedback site.

linux
سه شنبه 25 بهمن 1384, 17:21 عصر
هیچ کس به این مطلب آخری نگاه هم نداخت؟

M.kavyani
سه شنبه 05 اردیبهشت 1385, 23:18 عصر
با سلام
دوستان کسی در این مورد راه حلی پیدا نکرد. که بشه کانکشن استرینگ رو تغییر داد؟؟؟
آیا باید برای هر سیستمی کجددا" برنامه کمپایل بشه؟؟
( به دلایلی فقط میخوام از ویزارد استفداه کنم نگید کد نویسی کنم )
ممنون

reham
پنج شنبه 07 اردیبهشت 1385, 08:39 صبح
من تو 2003 از UDL استفاده کردم/و IPسرور و User \Pass رو اونجا خارج از برنامه تنظیم میکنم.
یه فایل Notepad با پسوند UDl و بعد تو برنامه با application.path از UDl مسیر سرور و پسورد رو میگیرم.البته گفتم از OledbConnetion باید استفاده کنیم نه SqlConnection.

M.kavyani
پنج شنبه 07 اردیبهشت 1385, 18:43 عصر
من تو 2003 از UDL استفاده کردم/و IPسرور و User \Pass رو اونجا خارج از برنامه تنظیم میکنم.
یه فایل Notepad با پسوند UDl و بعد تو برنامه با application.path از UDl مسیر سرور و پسورد رو میگیرم.البته گفتم از OledbConnetion باید استفاده کنیم نه SqlConnection.
دوست عزیز مبحث رو از ابتدا اگر میخوندید متوجه میشدید که صحبت ما در مود VS 2005 است و این بخش یکی از امکانات جدید 2005 است که در 2003 وجود نداشته .