I have an existing application build in C#.net, using SQL SERVER 2005, earlier application and SQL was on same machine, but now I need to connect SQL which is on server and is networked to the machine on which application is installed.
So can any one tell me how to connect SQL to application , and what changes need to be made in connection string.
Thanks
EDIT : I am a bit new to c#.net.
currently my connection string is : public SqlConnection con = new sqlConnection("server=.;database=Database1;integrated security=sspi); so if I just put this will it directly connect to the SQL which is on other computer ?
The answer depends on whether you are using SQL Server authentication
Standard Security (SQL Server authentication)
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
or to connect to a specific instance on the server
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
Trusted Connection
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
http://connectionstrings.com/sql-server-2005
Server=.;
Means you were connecting to a default instance of sql2005 on the same machine.
Since 2005 SQL Server has allowed instances.
So you could have MyMachine/MyLiveDBMSInstance and MyMachine/MyTestDBMSInstance.
Basically as though you'd installed sql server twice. Default (ie unnamed) instances were a backwards compatibility measure, so DBAs didn't have to go around explaining what an instance was to mere programmers. :)
You would have connected to them with Server = MyMachine\MyLiveDBMSInstance or perhaps
Server = .\MyInstance dot being this localhost basically.
So you can't use . any more, you need tthe name of the machine, and if it's using a named instance, you'll need that as well.
i.e Server = RemoteMachine or Server = RemoteMachine\InstanceName
Course all this assumes the machine with the dbms is on is set up correctly and the windows user running the application has been allowed access.
Related
I am working in a task in which my dot application have to access sql server 2012 instead of sql server 2000. Currently I don't have source code for the same and want to change it directly in connection string of web.config file.
I want to know that only changing connection string in deployed application is sufficient to access sql server 2012 database if its previous database was in sql server 2000.
In theory yes. Assuming that you get your security settings correct (in the updated connection string), the app should connect to the new DB. However... if the app used any features in SQL 2000 that are no longer available or compatible in SQL 2012, or used a weird DB driver, then you'll run into problems. It will probably be very apparent once you run your app.
Probably best if you can isolate the system (app + db server), placing into a VM environment. Then change the connection string and TEST TEST TEST.
I have a WebSite that just don't connect to database. Both are on my local machine.
Using the same parameters (Host, User ID, Pwd and Database) I can connect with the MS SQL Server Management Studio.
What can by my problem??
Here goes the two ConnectionStrings I'm trying to use:
Data Source=VIVID-28\MSSQLSERVER1;Initial Catalog=DicionarioDados;Persist Security Info=True;User ID=VIVID-28\Development;Password=*******
Server=VIVID-28\MSSQLSERVER1;Database=DicionarioDados;Integrated Security=SSPI;User ID=VIVID-28\Development;Password=*******
VIVID-28 Is the name of my machine.
MSSQLSERVER1 Is the Instance.
Try removing the "Integrated Security=SSPI" section. That means that it uses Windows Authentication and hence will ignore the user name and password you are passing in your connection string.
To test your connection you can try using VS server explorer and by adding connection to your sql server database you can test whether connection can be made with given parameters or not. ones you able to connect you can select the connection and go to properties and copy the connection string and past it as your application connection string.
There can be many reasons of this , see the following similar question and see the links I have given in the post, follow the steps.
Why I am not able to connect to remote SQL Server from asp.net website whereas it is connecting from SQL Server Management Studio
Do you work with multiple SQL Servers?
Are you absolutely sure that the SQL Management studio is connecting to the same sql server / instance as your code? If you have a production and development server, you may have created the user on your production server, but not development, or the password may be incorrect.
Try resetting the password on your development server and see where that takes you. (:
What is required to use a Windows form application use a SQL Server database thrugh network?
I want to install a SQL Server on 1 PC that has a Windows XP OS as a server. And, through a network I want the application to connect to a database.
So, I know that I should setup .Net Framework 4.0 to the application and I did a deployment to my project. I don't know if I need any application to install to do this connection like a server application or not?
Thanks in advance
The usual suspects / problems to access SQL remotely are:
Enable TCP/IP protocol in SQL server
Open up firewall to let SQL traffic through (usually port 1433)
Configure SQL server to allow remote connections, run Browser Service
Use the right credentials to address your SQL server instance
There are four basic things that are required...
There are limits on installing
server software on a desktop OS
(Traditional SQL server will not
install on XP) So you need to understand what you can install and where.
In your application there are choices as to "how to connect", but my experience is you want to use the .Net SQLClient
You need an understanding of how to
invoke an sql statement on the
server through direct sql or stored
procedures.
You need to understand what to expect in return from a query (nothing, scalar value, returned parameters, recordset...) and what to do with it when you get it...
For more information, please post examples of what you have tried, what the result was and what (specifically) you are trying to accomplish.
Edit after comment from #Marziana
As I read you comment I believe there are two questions:
How do I deploy the database to a
new server?
How do I connect my window forms
application to that new database?
1) Out of your original question, installing MS SQL server (standard edition) will NOT install on MS Windows XP. You need a Windows Server Software installation onto which you may install SQL Server. Your other option is to install a lesser edition of SQL Server to install on XP (such as SQL Desktop Edition, Evaluation Edition or Personal Edition).
2) The "Connection String" is the directive to the connection object telling what server to locate (and what instance of SQL on that server), which database to attach to on that server (the "initial catalog"), the security model to implement and the credentials (Username/password) to use if not using "integrated" security). If you "hard coded" your connection string then that makes it impossible to change the connection string to adapt to a new database server/dbname/credentials.
Beyond that your question is overly broad for a more direct answer.
SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=password;server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=30");
http://www.codeproject.com/KB/database/sql_in_csharp.aspx
Try that.
I'm trying to follow this example but I get an Exception related to the connection string telling me that the server was not found or was not accessible. The tutorial itself tells me on step 5 to "Change the connection string to point to your computer running SQL Server". I don't know if my SQL Server is running or not and if it is I don't know what would be the name of the server. I know I installed SQL Server when I installed VS 2010 (I did a full installation), so it should be somewhere. I haven't changed anything in the SQL Server configuration so everything should be on what is default.
If you installed SQL Server along with VS 2010, you have SQL Server 2008 Express edition on your machine, and it is installed by default as a "SQLExpress" instance, so your connection string would have to be something like:
server=(local)\SQLExpress;database=(whatever_you_want);integrated security=SSPI;
This would expect that database you specify to already exist on your server.
If you want to programmatically create a database, you would have to connect to the master database
server=(local)\SQLExpress;database=master;integrated security=SSPI;
and then run a SQL statement something like this from your app:
CREATE DATABASE (newDatabaseName)
You can check under services (start/run/services.msc) whether your SQL server is running or not; or in your start menu under "sql server configuration manager". pls check if named pipes and tcp-ip are enabled.
I am creating a window application that need to use sql server database.
I want to install this application to client machine without installing sql server so that my application can still connect to a database i.e mdf file that i will be providing at client system.
How can i connect to a database(mdf) on client machine through my window application without installing sql server. ?
I dont know is it possible or not.
If possible what will be the connection string in that case. Database need not be used in network.
Client mahine dont need any installation. Every thing needs to be run through pen drive
.mdf files are SQL Server database files. No other application can understand, read or update those files. If you need to open and mdf, you need a SQL instance. That instance can be local, can be an Express edition, or can be a remote one, doesn't matter. If your application needs a local SQL instance for it's own use then it can install SQL Server Express Edition when deployed.
You can try Sql Compact Edition or SqlLite. I think these are just a file based solution.
In that case you must have a server machine where your database files are stored. For that reason you have to use SQL Express Edition 2005 or 2008 in one machine and SQL server management studio to manage your database. Those are all free from Microsoft. The client machines will be connected through the connection string. Those machines don't need SQL instance or SQL server installed.
Regards..
You can search your MS-VS CD for SQLEXPRESS (please note the capital letters) and include it in your software when you create the set-up and your problem will be solved.
You don't have any other way except to use another database like access.
This database doesn't need its software.