How can I change the SQL Server Expess instance name / path - c#

I have a working SQL Server Express running in my computer as MYPC\SQLEXPRESS.
In my ASP.NET MVC 5 project I need to use this connection string in order to connect with it:
<add name="maymoneyDB"
connectionString="Server=MYPC\SQLEXPRESS;Initial Catalog=myDB;Integrated Security=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
The problem is that my coworkers have their SQL Server instances at . so I need to change the connection string each time I pull changes from TFS.
How can I change my server path? I try with link but seems to change ##SERVERNAME but not the path.
Any explanation about handle this situation is also helpful (maybe change the path is not the best approach).
Thanks

Related

MVC Application - Use your local DB in order to login/register

I'm new into MVC applications and I'm trying to learn how to connect to my local DB. I have watched lots of tutorials and I could figure it out how to change my connection string in order for the MVC to access my database. But, if I register on my MVC Application, Visual Studio creates automatically four new tables, besides my TEST database and the new user is inserted in those tables, not in the table I have set/used in connection string. What am I doing wrong? Thanks
Here is my connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=DESKTOP-K6CIG9A;Database=TEST;Trusted_Connection=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Here is how it looks my Server Explorer:
Printscreen
You're going to want to change your connection string to use (LocalDb)\v11.0. You can find more information in this article.

how should i use database of one sql machine in an another machine for my winform application?

I Have a C# windows form application which does many functions using the data from the database
Now I have a partner whose is working on the database part on his machine
He has database and i have all the forms and the application logic
How should i import his tables from his database engine ?
We both use SQL server 2008 R2 with database engines installed
I want that when i send my application to his machine (Say B) i should be able to use the database created by B to run the application of machine A(My machine ) ?
We are developing application in Visual studio 2010
Any help would be fantastic .
If it gets on a shared server, you can pull from different sources using different connection strings (using your database or his database, etc.). Here's a sample of connecting to 2 different database using 2 different connection strings in the Config file.
<connectionStrings>
<add name="Conn1" connectionString="Data Source=YourDataSource;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Conn2" connectionString="Data Source=YourDataSource;uid=YourUserID;pwd=YourPassword;" providerName="System.Data.OracleClient" />
</connectionStrings>
Copying a SQL Server Database will be helpful also, because if a database is on his local machine and neither of you are connected via LAN or some intranet, you can't access it. It needs to be copied or put on a shared server/location where both of you can access it. Otherwise, see the link on how to copy the database.
Copying data from one database to another. This link should also help accomplish the meat of your question.
However, if you solely want "B" to be able to access it, and you don't care about the access, then just deploy your executable and change the connection string in his config file.
Also, see Vladimir's post regarding 'Backup'.
Easiest thing to do would be to run full backup on database in question. Below is sample of backup script.
USE YourDatabaseName;
GO
BACKUP DATABASE YourDatabaseName
TO DISK = 'C:\Backup\YourDatabaseName.Bak'
WITH FORMAT,
MEDIANAME = 'C_FullBackup',
NAME = 'Full Backup of YourDatabaseName';
GO
Documentaion on BACKUP http://technet.microsoft.com/en-us/library/ms187510.aspx#TsqlProcedure
Once backup is done copy the file over to your machine. Now you need to restore database from backup.
RESTORE DATABASE YourDatabaseName
FROM DISK = N'(path to your BAK file)'
WITH FILE = 1,
MOVE N'(your DB name)' TO N'(your SQL path)database.MDF',
MOVE N'(your DB name)_LOG' TO N'(your SQL path)database_LOG.LDF',
NOUNLOAD,
REPLACE,
STATS = 10
GO
Documenation on RESTORE http://technet.microsoft.com/en-us/library/ms186858.aspx

Error to connect SQL Database at hosting website

did anybody host asp.net website with sql database?
I couldn't integrate my database connection with .mdf sql file (in my App_Data folder).
Is there anything need to change my data connection string (connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\example.mdf;Integrated Security=True;").
My host website: www.hostgator.com
It's really helpful if u give me proper suggestions step by step.
Database name is missing your Connection String :
Change as below:
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\example.mdf;Initial Catalog=mydatabase;Integrated Security=True;"
your connection string (connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\example.mdf;Integrated Security=True;") is the one you use when running locally. change it to the connection string that your hosting site gave you. it is usually on the database information.
After initial setup has been done, test your connecting weather it is successful or not then
write your connecting string as below:
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\example.mdf;Initial Catalog=yourDBname;Integrated Security=True;"
Where yourDBname is the name of your database that you have already given.
Hope this helps
Regards,
Rubel

WCF : remote SQL Server 2005 database connection

I'd like to know how to link my WCF application with a remote SQL Server database. By remote, I mean that is on the same network than me but not on the same computer/project.
I've the controll of the computer where the database is stored on.
What I've done so far : create my WCF application and try to add an ADO.NET connection. My issue : where to find the name of the server ? (and also : is it the good way to proceed ?).
Thanks !
where to find the name of the server?
Three options:
whoever "owns" the database server tells you the details, and you put them in a configuration file (or some other configuration system)
whoever "owns" the database server tells some key user the details, and the user puts them into a screen / api in the application
something like the above, but you try to discover sql servers at runtime via SqlDataSourceEnumerator (not a fan of this option, to be honest)
Conntion string should look like
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;
In Place of myServerName you can use IPAdress of machine
I suggest you add connectionString in the Web.config file of the application
<add name="connectionString"
connectionString="Data Source=ServerName/PC-Name;Initial Catalog=DatabaseName;User ID=userid;Password=pass"
providerName="System.Data.SqlClient" />
Use the connection string in your code/Logic
string conn = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;

Can't connect to shared hosting database with site

Slightly at my wits end. Built an application, running fine locally. Migrated my database to MSSQL without issue, uploaded the site, can't seem to get the application to connect to the database. Any page that accesses the database I get a generic error message.
I've tried all the separate combinations of connection strings I could think of using the Godaddy recommended connection strings. Perhaps I am overlooking something simple?
I'm using Entity Framework Code-First -- My context model is called CombosContext.
<add name="CombosContext" connectionString=" Server=jelatin.db.9508732.hostedresource.com; Database=jelatin; User ID=jelatin; Password=********; Trusted_Connection=False" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString=" Server=jelatin.db.9508732.hostedresource.com; Database=jelatin; User ID=jelatin; Password=********; Trusted_Connection=False" providerName="System.Data.SqlClient" />
Server: jelatin.db.9508732.hostedresource.com
DB name: jelatin
user: jelatin
Table: Comboes
I'm unfamiliar with GoDaddy hosted SQL, but usually a connection string to MS SQL Server uses "Data Source" instead of "Server" and "Initial Catalog" instead of "Database".
UPDATE
I didn't realize Server and Database were allowed options in the Connection String. Sorry for the confusion.
Regarding the database itself - are you letting EF create the database? Does the user have permission on GoDaddy's system to create a database?
If you have already created the database, did you populate anything? I have found that EF Code First won't correctly populate the database if the database exists and the metadata table doesn't. If you can, try copying your local database up to GoDaddy, and see if the connection works.
Finally, for your generic error message - is it coming back in a 500 error? If so, have you tried using either IE or Chrome's dev tools to inspect the response? Better error information is usually hidden in there.

Categories

Resources