I am transfering a Silverlight Application in Visual Studio 2010 from my old computer to my new computer, as I will no longer be programming on my old computer.
As I do not know how to transfer databases, I have completely remade the database on my new computer in MS Server 2008 R2.
When I load the Management Studio of Server 2008 R2, the 'Connect To Server' Dialog Box is accessed with the following info:
Server Type: Database Engine
Server Name: COMPUTER\SQLEXPRESSR2
Authentication: Windows Authentication
Username: jonas_000 [This is greyed out]
Password: [This is blank and greyed out]
Once it connects you can find my database under the 'Databases' tab and it is labeled 'MyDatabase'.
So when I go into my Visual Studio 2010 Express Silverlight project and look in the 'Database Explorer' pane, I have connected to this R2 database and it shows 'computer\sqlexpressr2.MyDatabase.dbo', and I can see all the tables I have created.
Now the Question.
In my project's Web.config file I have the following (which is for the OLD computer's setup):
<connectionStrings>
<add name="mydatabaseConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Admin\Documents\DB_MyWebSite.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
What should my new connectionStrings look like?
I cannot even see a mdf file on my new computer relating to MyDatabase.
Try this:
<connectionStrings>
<add name="mydatabaseConnectionString" connectionString="Data Source=COMPUTER\SQLEXPRESSR2;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
or
<connectionStrings>
<add name="mydatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESSR2;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
or
<connectionStrings>
<add name="mydatabaseConnectionString" connectionString="Data Source=(local)\SQLEXPRESSR2;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
The providerName attribute may be optional.
Also, you should run your app as jonas_000 for this to work (which is probably what you do when pressing F5 in Visual Studio).
Related
I created a small web application using Visual Web Developer 2010 Express. After I deployed my site and go to the first page, which is the login page that provides a list of users for the app, I get this error:
Exception Details: System.Data.SqlClient.SqlException: User does not have permission to perform this action.
Source Error:
Line 22: public ActionResult LogOn()
Line 23: {
Line 24: var users = Membership.GetAllUsers().Cast<MembershipUser>().ToList();
Line 25: SelectList usernames = new SelectList(users);
Line 26: ViewBag.UserNames = usernames;
Here is my connectionStrings settings:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Why is this error occurring? Any help is much appreciated. I'm currently developing it on a Windows 2008 Server and testing the deployment of it on the same machine.
I found the issue with my connection string. It was set up for user instancing, which according to this Microsoft article:
Web applications running on IIS 7.5 and that rely on SQL Server
Express user instancing will fail to run using the default IIS 7.5
security configuration on both Windows 7 Client and Windows Server
2008 R2
The article also recommends avoiding usage of user instances in production. I found this post which helped me host the database in a normal .\SQLExpress instance. I changed my connection strings to:
<connectionStrings>
<add name="ApplicationServices"
connectionString="Database="app_users";Data Source=.\SQLEXPRESS;Initial Catalog=app_users;Integrated Security=SSPI;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Before changing the above connection string, I attached the aspnetdb.mdf file in SQL Server Express to a new database I created called "app_users".
I no longer get the permissions error.
I am developing an ASP.NET MVC3 application using,
MS SQL Server Pro 2008
MS VS 2010 pro
Entity FrameWork as model class.
When i start ASP.NET Web Site Administration Tool by clicking ASP.NET Configuration from solution explorer, in Security tab it shows an error:
Unable to connect to SQL Server database.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config has a connection string as,
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\MSSQLSERVER;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
I opened the
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe
and configure the database default named 'aspnetdb'. But situation is not being improved. So, would you please help me to solve it.
Thank you.
Have you tried the database server that Visual Studio attempts to use?
It should match the one specified in your web.config file.
To check to go: Tools -> Options -> Database Tools -> Design-time Validation Database.
You can then change the SQL Server instance which is used.
I am newbie and confused how to do it.
I have built MVC 3 application in Visual Studio 2010 and published to the localhost and it's working fine.
Here, What I actually want is to use the Sql Server 2008 installed in my computer rather than database under the folder APP_DATA that I have created using visual studio.
I am new to the MVC and don't know about the database connection detailly. Following is the connection string of the web.config file:
<connectionStrings>
<add name="IVRControlPanelEntities" connectionString="metadata=res://*/Models.IVRControlPanelModel.csdl|res://*/Models.IVRControlPanelModel.ssdl|res://*/Models.IVRControlPanelModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\IVRControlPanelDB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
This is the connectionstring automatically added by the visual studio while adding the data entity model.
After published to localhost the database used by mvc 3 is under the APP_DATA folder of wwwroot folder.
What I need to change to connect to the Sql Server 2008 installed in my computer rather than database created on the Visual Studio.
One more thing, I could not import the database created by visual studio to the sql server 2008 which is in the form IVRControlPanelDB.mdf
You should use Database.SetInitializer<> method in Application_Start method in Global.asax
read this and this ,this article may help too.
You need to modify your connectionstring to add the address to your sql server. Example:
<connectionStrings>
<add name="ApplicationServices"
connectionString="Server=localhost;Database=myDatabase;User Id=myUser;Password=myPassword;"
providerName="System.Data.SqlClient" />
</connectionStrings>
i have published my asp.net MVC 3 web application locally using IIS 7 express and visual developer express 2010, but when i tired to login to the application it returned the following error:-
System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to a failure in impersonating the client. The connection will be closed.
so what might be causing this problme?
BR
Edit:-
the current connection string is :-
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="ElearningEntities" connectionString="metadata=res://*/Models.Elearning.csdl|res://*/Models.Elearning.ssdl|res://*/Models.Elearning.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MScProject.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
If you have enabled SSPI in your connection string, you might no longer be able to perform it when the SQL server is on a separate tier than your web server. You could use standard SQL Server authentication with a username and password in this case.
I have installed visual studio 2010 as well as mvc 3 and have been working on a site.
Later I installed sql server 2008 and when I tried to register a user through provided membership in asp.net mvc i had bunch of errors saying that there was no data base or something like that, so through a lot of research i finally added the aspnetdb to my sql server and enabled remote accessing... and as of right now when i try to register i get this error: Unable to connect to SQL Server database.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
this is my connection string:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
I remember that some time ago working on my previous projects i had no problem with the membership provider and registering users loging in and so on.. so i'm really frustrated and don't know what i'm missing here.
You can use it directly from localhost, no need to put it in App_Data folder. Use this connection string:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=*Name of your database*;Integrated Security=SSPI"/>
</connectionStrings>