العديد من الاخوة يواجه مشاكل مع الasp.net2 خاصة عند استخدام ميزات ال Membership ,Profile ,Personlization
المشلكة الاولى هي ان المواقع المنشاة تستخدم الSQLServer Express Edition افتراضيا لربط هذه الخدمات مع الموقع او التطبيق
للتغلب على هذه المشكلة يجب اولا ان نعرف ان استخدام التطبيق ل SQLServer Express يتم عن طريق الملف machine.config الموجود تحت C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG
حيث نجد ان هناك connectionstring معرف باسم LocalSqlServer وهو مربوط على ال SQLServer Express وسيحاول الويب سيرفر دائما الاتصال بقاعدة البيانات هذه لانه يعتبرها قاعدة البيانات الافتراضية .لاحظ معي الconnectionstring:
<connectionStrings> <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings>
تلاحظ انه يربطك بسيرفر الاكسبريس وهو ما سبب اغلب المشاكل و الاخطاء التي تظهر خاصة هذه الاخطاء:
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store. The following message may help in diagnosing the problem: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'
و
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
الحل:
اولا :استخدم البرنامج C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe لانشاء قاعدة البيانات الخاصة بميزات
Membership ,Profile ,Personlization
ثانيا:غير محتوى الweb.config كي يؤشر على قاعدة البيانات الصحيحة.ولعمل ذلك هناك خياران:
اما ان تعمل override لنص الاتصال المسمى LocalSqlServer في ال web.config باستخدام الخاصية clear كالتالي:
<connectionStrings> <clear /> <add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnetdb;uid=myusername;pwd=mypassword" providerName="System.Data.SqlClient" /> </connectionStrings>
وهو الحل الاسهل.
او ان تقوم بانشاء provider جديدة باستخدام نص الاتصال الجديد aspnetdbConnectionString:
<connectionStrings> <add name="aspnetdbConnectionString" connectionString="Data Source=localhost;Initial Catalog=aspnetdb;uid=myusername;pwd=mypassword" providerName="System.Data.SqlClient" /> </connectionStrings>
ثم انشيء ال providers الجديدة باستخدام نص الاتصال aspnetdbConnectionString تحت <system.web>
<membership defaultProvider="MadaniMembershipProvider" > <providers> <clear /> <add name="MadaniMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="aspnetdbConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="MinimumDefinition" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" /> </providers> </membership> <profile defaultProvider="MadaniProfileProvider" > <providers> <clear /> <add name="MadaniProfileProvider" connectionStringName="aspnetdbConnectionString" applicationName="MinimumDefinition" type="System.Web.Profile.SqlProfileProvider" /> </providers> </profile> <roleManager enabled="true" defaultProvider="MadaniRoleProvider"> <providers> <clear /> <add connectionStringName="aspnetdbConnectionString" applicationName="MinimumDefinition" name="MadaniRoleProvider" type="System.Web.Security.SqlRoleProvider" /> </providers> </roleManager>
الان لو استخدمنا اداة Web Site Administration Tool و ذهبنا الى قسم الproviders سنرى الproviders بالاسماء :MadaniMembershipProvider ,MadaniRoleProvider
يجب الانتباه الى الخاصية applicationName حيث يجب تغييرها الى اسم التطبيق الذي تعمل عليه اذا كنت تود استخدام الprovider في هذا التطبيق فقط .والخاصية connectionStringName يجب ان تكون موافقة لاسم نص الاتصال اي aspnetdbConnectionString
تحياتي
مدني